1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_shell.hxx"
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 #include <osl/diagnose.h>
31 #include "cmdmailmsg.hxx"
32 #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
33 #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/uno/RuntimeException.hpp>
36 
37 //------------------------------------------------------------------------
38 // namespace directives
39 //------------------------------------------------------------------------
40 
41 using com::sun::star::lang::IllegalArgumentException;
42 using com::sun::star::lang::WrappedTargetException;
43 using com::sun::star::container::NoSuchElementException;
44 using com::sun::star::container::XNameAccess;
45 using rtl::OUString;
46 using osl::MutexGuard;
47 
48 using namespace cppu;
49 using namespace com::sun::star::uno;
50 
51 
52 //------------------------------------------------
53 //
54 //------------------------------------------------
55 
56 void SAL_CALL CmdMailMsg::setRecipient( const ::rtl::OUString& aRecipient )
57     throw (RuntimeException)
58 {
59     MutexGuard aGuard( m_aMutex );
60     m_aRecipient = aRecipient;
61 }
62 
63 //------------------------------------------------
64 //
65 //------------------------------------------------
66 
67 ::rtl::OUString SAL_CALL CmdMailMsg::getRecipient(  )
68     throw (RuntimeException)
69 {
70     MutexGuard aGuard( m_aMutex );
71     return m_aRecipient;
72 }
73 
74 //------------------------------------------------
75 //
76 //------------------------------------------------
77 
78 void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient )
79     throw (RuntimeException)
80 {
81     MutexGuard aGuard( m_aMutex );
82     m_CcRecipients = aCcRecipient;
83 }
84 
85 //------------------------------------------------
86 //
87 //------------------------------------------------
88 
89 Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient(  )
90     throw (RuntimeException)
91 {
92     MutexGuard aGuard( m_aMutex );
93     return m_CcRecipients;
94 }
95 
96 //------------------------------------------------
97 //
98 //------------------------------------------------
99 
100 void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient )
101     throw (RuntimeException)
102 {
103     MutexGuard aGuard( m_aMutex );
104     m_BccRecipients = aBccRecipient;
105 }
106 
107 //------------------------------------------------
108 //
109 //------------------------------------------------
110 
111 Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient(  )
112     throw (RuntimeException)
113 {
114     MutexGuard aGuard( m_aMutex );
115     return m_BccRecipients;
116 }
117 
118 //------------------------------------------------
119 //
120 //------------------------------------------------
121 
122 void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator )
123     throw (RuntimeException)
124 {
125     MutexGuard aGuard( m_aMutex );
126     m_aOriginator = aOriginator;
127 }
128 
129 //------------------------------------------------
130 //
131 //------------------------------------------------
132 
133 OUString SAL_CALL CmdMailMsg::getOriginator(  )
134     throw (RuntimeException)
135 {
136     MutexGuard aGuard( m_aMutex );
137     return m_aOriginator;
138 }
139 
140 //------------------------------------------------
141 //
142 //------------------------------------------------
143 
144 void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject )
145     throw (RuntimeException)
146 {
147     MutexGuard aGuard( m_aMutex );
148     m_aSubject = aSubject;
149 }
150 
151 //------------------------------------------------
152 //
153 //------------------------------------------------
154 
155 OUString SAL_CALL CmdMailMsg::getSubject(  )
156     throw (RuntimeException)
157 {
158     MutexGuard aGuard( m_aMutex );
159     return m_aSubject;
160 }
161 
162 //------------------------------------------------
163 //
164 //------------------------------------------------
165 
166 void SAL_CALL CmdMailMsg::setAttachement( const Sequence< ::rtl::OUString >& aAttachment )
167     throw (IllegalArgumentException, RuntimeException)
168 {
169     MutexGuard aGuard( m_aMutex );
170     m_Attachments = aAttachment;
171 }
172 
173 //------------------------------------------------
174 //
175 //------------------------------------------------
176 
177 Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement(  )
178     throw (RuntimeException)
179 {
180     MutexGuard aGuard( m_aMutex );
181     return m_Attachments;
182 }
183 
184 //------------------------------------------------
185 //
186 //------------------------------------------------
187 
188 Any SAL_CALL CmdMailMsg::getByName( const OUString& aName )
189     throw (NoSuchElementException, WrappedTargetException, RuntimeException)
190 {
191     MutexGuard aGuard( m_aMutex );
192 
193     if( 0 == aName.compareToAscii( "from" ) &&  m_aOriginator.getLength() )
194         return makeAny( m_aOriginator );
195 
196     else if( 0 == aName.compareToAscii( "to" ) &&  m_aRecipient.getLength() )
197         return makeAny( m_aRecipient );
198 
199     else if( 0 == aName.compareToAscii( "cc" ) &&  m_CcRecipients.getLength() )
200         return makeAny( m_CcRecipients );
201 
202     else if( 0 == aName.compareToAscii( "bcc" ) &&  m_BccRecipients.getLength() )
203         return makeAny( m_BccRecipients );
204 
205     else if( 0 == aName.compareToAscii( "subject" ) &&  m_aSubject.getLength() )
206         return makeAny( m_aSubject );
207 
208     else if( 0 == aName.compareToAscii( "attachment" ) &&  m_Attachments.getLength() )
209         return makeAny( m_Attachments );
210 
211    throw NoSuchElementException( OUString::createFromAscii( "key not found: ") + aName,
212         static_cast < XNameAccess * > (this) );
213 }
214 
215 //------------------------------------------------
216 //
217 //------------------------------------------------
218 
219 Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames(  )
220     throw (::com::sun::star::uno::RuntimeException)
221 {
222     MutexGuard aGuard( m_aMutex );
223 
224     sal_Int32 nItems = 0;
225     Sequence< OUString > aRet( 6 );
226 
227     if( m_aOriginator.getLength() )
228         aRet[nItems++] = OUString::createFromAscii( "from" );
229 
230     if( m_aRecipient.getLength() )
231         aRet[nItems++] = OUString::createFromAscii( "to" );
232 
233     if( m_CcRecipients.getLength() )
234         aRet[nItems++] = OUString::createFromAscii( "cc" );
235 
236     if( m_BccRecipients.getLength() )
237         aRet[nItems++] = OUString::createFromAscii( "bcc" );
238 
239     if( m_aSubject.getLength() )
240         aRet[nItems++] = OUString::createFromAscii( "subject" );
241 
242     if( m_Attachments.getLength() )
243         aRet[nItems++] = OUString::createFromAscii( "attachment" );
244 
245     aRet.realloc( nItems );
246     return aRet;
247 }
248 
249 //------------------------------------------------
250 //
251 //------------------------------------------------
252 
253  sal_Bool SAL_CALL CmdMailMsg::hasByName( const ::rtl::OUString& aName )
254     throw (RuntimeException)
255 {
256     MutexGuard aGuard( m_aMutex );
257 
258     if( 0 == aName.compareToAscii( "from" ) &&  m_aOriginator.getLength() )
259         return sal_True;
260 
261     else if( 0 == aName.compareToAscii( "to" ) &&  m_aRecipient.getLength() )
262         return sal_True;
263 
264     else if( 0 == aName.compareToAscii( "cc" ) &&  m_CcRecipients.getLength() )
265         return sal_True;
266 
267     else if( 0 == aName.compareToAscii( "bcc" ) &&  m_BccRecipients.getLength() )
268         return sal_True;
269 
270     else if( 0 == aName.compareToAscii( "subject" ) &&  m_aSubject.getLength() )
271         return sal_True;
272 
273     else if( 0 == aName.compareToAscii( "attachment" ) &&  m_Attachments.getLength() )
274         return sal_True;
275 
276     return sal_False;
277 }
278 
279 //------------------------------------------------
280 //
281 //------------------------------------------------
282 
283 Type SAL_CALL CmdMailMsg::getElementType(  )
284     throw (RuntimeException)
285 {
286     // returning void for multi type container
287     return Type();
288 }
289 
290 //------------------------------------------------
291 //
292 //------------------------------------------------
293 
294 sal_Bool SAL_CALL CmdMailMsg::hasElements(  )
295     throw (RuntimeException)
296 {
297     return 0 != getElementNames().getLength();
298 }
299