1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 #include <osl/diagnose.h>
35 #include "cmdmailmsg.hxx"
36 #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
37 #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
38 #include <com/sun/star/uno/Reference.hxx>
39 #include <com/sun/star/uno/RuntimeException.hpp>
40 
41 //------------------------------------------------------------------------
42 // namespace directives
43 //------------------------------------------------------------------------
44 
45 using com::sun::star::lang::IllegalArgumentException;
46 using com::sun::star::lang::WrappedTargetException;
47 using com::sun::star::container::NoSuchElementException;
48 using com::sun::star::container::XNameAccess;
49 using rtl::OUString;
50 using osl::MutexGuard;
51 
52 using namespace cppu;
53 using namespace com::sun::star::uno;
54 
55 
56 //------------------------------------------------
57 //
58 //------------------------------------------------
59 
60 void SAL_CALL CmdMailMsg::setRecipient( const ::rtl::OUString& aRecipient )
61     throw (RuntimeException)
62 {
63     MutexGuard aGuard( m_aMutex );
64     m_aRecipient = aRecipient;
65 }
66 
67 //------------------------------------------------
68 //
69 //------------------------------------------------
70 
71 ::rtl::OUString SAL_CALL CmdMailMsg::getRecipient(  )
72     throw (RuntimeException)
73 {
74     MutexGuard aGuard( m_aMutex );
75     return m_aRecipient;
76 }
77 
78 //------------------------------------------------
79 //
80 //------------------------------------------------
81 
82 void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient )
83     throw (RuntimeException)
84 {
85     MutexGuard aGuard( m_aMutex );
86     m_CcRecipients = aCcRecipient;
87 }
88 
89 //------------------------------------------------
90 //
91 //------------------------------------------------
92 
93 Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient(  )
94     throw (RuntimeException)
95 {
96     MutexGuard aGuard( m_aMutex );
97     return m_CcRecipients;
98 }
99 
100 //------------------------------------------------
101 //
102 //------------------------------------------------
103 
104 void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient )
105     throw (RuntimeException)
106 {
107     MutexGuard aGuard( m_aMutex );
108     m_BccRecipients = aBccRecipient;
109 }
110 
111 //------------------------------------------------
112 //
113 //------------------------------------------------
114 
115 Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient(  )
116     throw (RuntimeException)
117 {
118     MutexGuard aGuard( m_aMutex );
119     return m_BccRecipients;
120 }
121 
122 //------------------------------------------------
123 //
124 //------------------------------------------------
125 
126 void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator )
127     throw (RuntimeException)
128 {
129     MutexGuard aGuard( m_aMutex );
130     m_aOriginator = aOriginator;
131 }
132 
133 //------------------------------------------------
134 //
135 //------------------------------------------------
136 
137 OUString SAL_CALL CmdMailMsg::getOriginator(  )
138     throw (RuntimeException)
139 {
140     MutexGuard aGuard( m_aMutex );
141     return m_aOriginator;
142 }
143 
144 //------------------------------------------------
145 //
146 //------------------------------------------------
147 
148 void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject )
149     throw (RuntimeException)
150 {
151     MutexGuard aGuard( m_aMutex );
152     m_aSubject = aSubject;
153 }
154 
155 //------------------------------------------------
156 //
157 //------------------------------------------------
158 
159 OUString SAL_CALL CmdMailMsg::getSubject(  )
160     throw (RuntimeException)
161 {
162     MutexGuard aGuard( m_aMutex );
163     return m_aSubject;
164 }
165 
166 //------------------------------------------------
167 //
168 //------------------------------------------------
169 
170 void SAL_CALL CmdMailMsg::setAttachement( const Sequence< ::rtl::OUString >& aAttachment )
171     throw (IllegalArgumentException, RuntimeException)
172 {
173     MutexGuard aGuard( m_aMutex );
174     m_Attachments = aAttachment;
175 }
176 
177 //------------------------------------------------
178 //
179 //------------------------------------------------
180 
181 Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement(  )
182     throw (RuntimeException)
183 {
184     MutexGuard aGuard( m_aMutex );
185     return m_Attachments;
186 }
187 
188 //------------------------------------------------
189 //
190 //------------------------------------------------
191 
192 Any SAL_CALL CmdMailMsg::getByName( const OUString& aName )
193     throw (NoSuchElementException, WrappedTargetException, RuntimeException)
194 {
195     MutexGuard aGuard( m_aMutex );
196 
197     if( 0 == aName.compareToAscii( "from" ) &&  m_aOriginator.getLength() )
198         return makeAny( m_aOriginator );
199 
200     else if( 0 == aName.compareToAscii( "to" ) &&  m_aRecipient.getLength() )
201         return makeAny( m_aRecipient );
202 
203     else if( 0 == aName.compareToAscii( "cc" ) &&  m_CcRecipients.getLength() )
204         return makeAny( m_CcRecipients );
205 
206     else if( 0 == aName.compareToAscii( "bcc" ) &&  m_BccRecipients.getLength() )
207         return makeAny( m_BccRecipients );
208 
209     else if( 0 == aName.compareToAscii( "subject" ) &&  m_aSubject.getLength() )
210         return makeAny( m_aSubject );
211 
212     else if( 0 == aName.compareToAscii( "attachment" ) &&  m_Attachments.getLength() )
213         return makeAny( m_Attachments );
214 
215    throw NoSuchElementException( OUString::createFromAscii( "key not found: ") + aName,
216         static_cast < XNameAccess * > (this) );
217 }
218 
219 //------------------------------------------------
220 //
221 //------------------------------------------------
222 
223 Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames(  )
224     throw (::com::sun::star::uno::RuntimeException)
225 {
226     MutexGuard aGuard( m_aMutex );
227 
228     sal_Int32 nItems = 0;
229     Sequence< OUString > aRet( 6 );
230 
231     if( m_aOriginator.getLength() )
232         aRet[nItems++] = OUString::createFromAscii( "from" );
233 
234     if( m_aRecipient.getLength() )
235         aRet[nItems++] = OUString::createFromAscii( "to" );
236 
237     if( m_CcRecipients.getLength() )
238         aRet[nItems++] = OUString::createFromAscii( "cc" );
239 
240     if( m_BccRecipients.getLength() )
241         aRet[nItems++] = OUString::createFromAscii( "bcc" );
242 
243     if( m_aSubject.getLength() )
244         aRet[nItems++] = OUString::createFromAscii( "subject" );
245 
246     if( m_Attachments.getLength() )
247         aRet[nItems++] = OUString::createFromAscii( "attachment" );
248 
249     aRet.realloc( nItems );
250     return aRet;
251 }
252 
253 //------------------------------------------------
254 //
255 //------------------------------------------------
256 
257  sal_Bool SAL_CALL CmdMailMsg::hasByName( const ::rtl::OUString& aName )
258     throw (RuntimeException)
259 {
260     MutexGuard aGuard( m_aMutex );
261 
262     if( 0 == aName.compareToAscii( "from" ) &&  m_aOriginator.getLength() )
263         return sal_True;
264 
265     else if( 0 == aName.compareToAscii( "to" ) &&  m_aRecipient.getLength() )
266         return sal_True;
267 
268     else if( 0 == aName.compareToAscii( "cc" ) &&  m_CcRecipients.getLength() )
269         return sal_True;
270 
271     else if( 0 == aName.compareToAscii( "bcc" ) &&  m_BccRecipients.getLength() )
272         return sal_True;
273 
274     else if( 0 == aName.compareToAscii( "subject" ) &&  m_aSubject.getLength() )
275         return sal_True;
276 
277     else if( 0 == aName.compareToAscii( "attachment" ) &&  m_Attachments.getLength() )
278         return sal_True;
279 
280     return sal_False;
281 }
282 
283 //------------------------------------------------
284 //
285 //------------------------------------------------
286 
287 Type SAL_CALL CmdMailMsg::getElementType(  )
288     throw (RuntimeException)
289 {
290     // returning void for multi type container
291     return Type();
292 }
293 
294 //------------------------------------------------
295 //
296 //------------------------------------------------
297 
298 sal_Bool SAL_CALL CmdMailMsg::hasElements(  )
299     throw (RuntimeException)
300 {
301     return 0 != getElementNames().getLength();
302 }
303