xref: /AOO41X/main/sfx2/source/dialog/mailmodel.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir // includes --------------------------------------------------------------
31*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
38*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/system/SimpleMailClientFlags.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/security/CertificateValidity.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/security/DocumentSignatureInformation.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
58*cdf0e10cSrcweir #include <rtl/textenc.h>
59*cdf0e10cSrcweir #include <rtl/uri.h>
60*cdf0e10cSrcweir #include <rtl/uri.hxx>
61*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
62*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <sfx2/mailmodelapi.hxx>
65*cdf0e10cSrcweir #include "sfxtypes.hxx"
66*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
67*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
68*cdf0e10cSrcweir #include "dialog.hrc"
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
71*cdf0e10cSrcweir #include <unotools/configitem.hxx>
72*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
73*cdf0e10cSrcweir #include <tools/urlobj.hxx>
74*cdf0e10cSrcweir #include <unotools/useroptions.hxx>
75*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
76*cdf0e10cSrcweir #include <comphelper/extract.hxx>
77*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
78*cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
79*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
80*cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
81*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
82*cdf0e10cSrcweir #include <vcl/svapp.hxx>
83*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir // --------------------------------------------------------------
86*cdf0e10cSrcweir using namespace ::com::sun::star;
87*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
88*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
89*cdf0e10cSrcweir using namespace ::com::sun::star::io;
90*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
91*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
92*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
93*cdf0e10cSrcweir using namespace ::com::sun::star::util;
94*cdf0e10cSrcweir using namespace ::com::sun::star::system;
95*cdf0e10cSrcweir using namespace ::rtl;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir namespace css = ::com::sun::star;
98*cdf0e10cSrcweir // - class PrepareListener_Impl ------------------------------------------
99*cdf0e10cSrcweir class PrepareListener_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     bool m_bState;
102*cdf0e10cSrcweir public:
103*cdf0e10cSrcweir         PrepareListener_Impl();
104*cdf0e10cSrcweir         virtual ~PrepareListener_Impl();
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         // css.frame.XStatusListener
107*cdf0e10cSrcweir         virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent)
108*cdf0e10cSrcweir           throw(css::uno::RuntimeException);
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         // css.lang.XEventListener
111*cdf0e10cSrcweir         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
112*cdf0e10cSrcweir           throw(css::uno::RuntimeException);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         bool IsSet() const {return m_bState;}
115*cdf0e10cSrcweir };
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /*-- 25.08.2010 14:32:49---------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
120*cdf0e10cSrcweir PrepareListener_Impl::PrepareListener_Impl() :
121*cdf0e10cSrcweir     m_bState( false )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir /*-- 25.08.2010 14:32:51---------------------------------------------------
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
127*cdf0e10cSrcweir PrepareListener_Impl::~PrepareListener_Impl()
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir /*-- 25.08.2010 14:32:51---------------------------------------------------
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
133*cdf0e10cSrcweir void PrepareListener_Impl::statusChanged(const css::frame::FeatureStateEvent& rEvent) throw(css::uno::RuntimeException)
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     if( rEvent.IsEnabled )
136*cdf0e10cSrcweir         rEvent.State >>= m_bState;
137*cdf0e10cSrcweir     else
138*cdf0e10cSrcweir         m_bState = sal_False;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir /*-- 25.08.2010 14:32:52---------------------------------------------------
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
143*cdf0e10cSrcweir void PrepareListener_Impl::disposing(const css::lang::EventObject& /*rEvent*/) throw(css::uno::RuntimeException)
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir // class AddressList_Impl ------------------------------------------------
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir typedef String* AddressItemPtr_Impl;
150*cdf0e10cSrcweir DECLARE_LIST( AddressList_Impl, AddressItemPtr_Impl )
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir // class SfxMailModel -----------------------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir static const char       PDF_DOCUMENT_TYPE[]   = "pdf_Portable_Document_Format";
155*cdf0e10cSrcweir static const sal_uInt32 PDF_DOCUMENT_TYPE_LEN = 28;
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir void SfxMailModel::ClearList( AddressList_Impl* pList )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	if ( pList )
160*cdf0e10cSrcweir 	{
161*cdf0e10cSrcweir 		sal_uIntPtr i, nCount = pList->Count();
162*cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
163*cdf0e10cSrcweir 			delete pList->GetObject(i);
164*cdf0e10cSrcweir 		pList->Clear();
165*cdf0e10cSrcweir 	}
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void SfxMailModel::MakeValueList( AddressList_Impl* pList, String& rValueList )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	rValueList.Erase();
171*cdf0e10cSrcweir 	if ( pList )
172*cdf0e10cSrcweir 	{
173*cdf0e10cSrcweir 		sal_uIntPtr i, nCount = pList->Count();
174*cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
175*cdf0e10cSrcweir 		{
176*cdf0e10cSrcweir 			if ( rValueList.Len() > 0 )
177*cdf0e10cSrcweir 				rValueList += ',';
178*cdf0e10cSrcweir 			rValueList += *pList->GetObject(i);
179*cdf0e10cSrcweir 		}
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir sal_Bool HasDocumentValidSignature( const css::uno::Reference< css::frame::XModel >& xModel )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     try
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertySet > xPropSet( xModel, css::uno::UNO_QUERY );
188*cdf0e10cSrcweir         if ( xPropSet.is() )
189*cdf0e10cSrcweir         {
190*cdf0e10cSrcweir             Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasValidSignatures" )));
191*cdf0e10cSrcweir             sal_Bool bReturn = sal_Bool();
192*cdf0e10cSrcweir             if ( a >>= bReturn )
193*cdf0e10cSrcweir                 return bReturn;
194*cdf0e10cSrcweir         }
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir     catch ( css::uno::RuntimeException& )
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         throw;
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir     catch ( css::uno::Exception& )
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     return sal_False;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir SfxMailModel::SaveResult SfxMailModel::ShowFilterOptionsDialog(
208*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMGR,
209*cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel,
210*cdf0e10cSrcweir     const rtl::OUString& rFilterName,
211*cdf0e10cSrcweir     const rtl::OUString& rType,
212*cdf0e10cSrcweir     bool bModified,
213*cdf0e10cSrcweir     sal_Int32& rNumArgs,
214*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     SaveResult eRet( SAVE_ERROR );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     try
219*cdf0e10cSrcweir     {
220*cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aProps;
221*cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG =
222*cdf0e10cSrcweir                 uno::Reference< container::XNameAccess >(
223*cdf0e10cSrcweir                     xSMGR->createInstance(
224*cdf0e10cSrcweir                         ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
225*cdf0e10cSrcweir         css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY );
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         if ( !xFilterCFG.is() )
228*cdf0e10cSrcweir             return eRet;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         uno::Any aAny = xFilterCFG->getByName( rFilterName );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         if ( aAny >>= aProps )
233*cdf0e10cSrcweir         {
234*cdf0e10cSrcweir             sal_Int32 nPropertyCount = aProps.getLength();
235*cdf0e10cSrcweir             for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
236*cdf0e10cSrcweir             {
237*cdf0e10cSrcweir                 if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii( "UIComponent" )) )
238*cdf0e10cSrcweir                 {
239*cdf0e10cSrcweir                     ::rtl::OUString aServiceName;
240*cdf0e10cSrcweir                     aProps[nProperty].Value >>= aServiceName;
241*cdf0e10cSrcweir                     if( aServiceName.getLength() )
242*cdf0e10cSrcweir                     {
243*cdf0e10cSrcweir                         uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog(
244*cdf0e10cSrcweir                             xSMGR->createInstance( aServiceName ), uno::UNO_QUERY );
245*cdf0e10cSrcweir                         uno::Reference< beans::XPropertyAccess > xFilterProperties(
246*cdf0e10cSrcweir                             xFilterDialog, uno::UNO_QUERY );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir                         if( xFilterDialog.is() && xFilterProperties.is() )
249*cdf0e10cSrcweir                         {
250*cdf0e10cSrcweir                             uno::Sequence< beans::PropertyValue > aPropsForDialog(1);
251*cdf0e10cSrcweir                             uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir                             if ( rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN ))
254*cdf0e10cSrcweir                             {
255*cdf0e10cSrcweir                                 //add an internal property, used to tell the dialog we want to set a different
256*cdf0e10cSrcweir                                 //string for the ok button
257*cdf0e10cSrcweir                                 //used in filter/source/pdf/impdialog.cxx
258*cdf0e10cSrcweir                                 String aOkSendText( SfxResId( STR_PDF_EXPORT_SEND ));
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir                                 uno::Sequence< beans::PropertyValue > aFilterDataValue(1);
261*cdf0e10cSrcweir                                 aFilterDataValue[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_OkButtonString" ));
262*cdf0e10cSrcweir                                 aFilterDataValue[0].Value = css::uno::makeAny( ::rtl::OUString( aOkSendText ));
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir                                 //add to the filterdata property, the only one the PDF export filter dialog will care for
265*cdf0e10cSrcweir                                 aPropsForDialog[0].Name =  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ));
266*cdf0e10cSrcweir                                 aPropsForDialog[0].Value = css::uno::makeAny( aFilterDataValue );
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir                                 //when executing the dialog will merge the persistent FilterData properties
269*cdf0e10cSrcweir                                 xFilterProperties->setPropertyValues( aPropsForDialog );
270*cdf0e10cSrcweir                             }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir                             if( xExporter.is() )
273*cdf0e10cSrcweir                                 xExporter->setSourceDocument(
274*cdf0e10cSrcweir                                     uno::Reference< lang::XComponent >( xModel, uno::UNO_QUERY ) );
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir                             if( xFilterDialog->execute() )
277*cdf0e10cSrcweir                             {
278*cdf0e10cSrcweir                                 //get the filter data
279*cdf0e10cSrcweir                                 uno::Sequence< beans::PropertyValue > aPropsFromDialog = xFilterProperties->getPropertyValues();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir                                 //add them to the args
282*cdf0e10cSrcweir                                 for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ )
283*cdf0e10cSrcweir                                 {
284*cdf0e10cSrcweir                                     if( aPropsFromDialog[ nInd ].Name.equals( ::rtl::OUString::createFromAscii( "FilterData" ) ) )
285*cdf0e10cSrcweir                                     {
286*cdf0e10cSrcweir                                         //found the filterdata, add to the storing argument
287*cdf0e10cSrcweir                                         rArgs.realloc( ++rNumArgs );
288*cdf0e10cSrcweir                                         rArgs[rNumArgs-1].Name = aPropsFromDialog[ nInd ].Name;
289*cdf0e10cSrcweir                                         rArgs[rNumArgs-1].Value = aPropsFromDialog[ nInd ].Value;
290*cdf0e10cSrcweir                                         break;
291*cdf0e10cSrcweir                                     }
292*cdf0e10cSrcweir                                 }
293*cdf0e10cSrcweir                                 eRet = SAVE_SUCCESSFULL;
294*cdf0e10cSrcweir                             }
295*cdf0e10cSrcweir                             else
296*cdf0e10cSrcweir                             {
297*cdf0e10cSrcweir                                 // cancel from dialog, then do not send
298*cdf0e10cSrcweir                                 // If the model is not modified, it could be modified by the dispatch calls.
299*cdf0e10cSrcweir                                 // Therefore set back to modified = false. This should not hurt if we call
300*cdf0e10cSrcweir                                 // on a non-modified model.
301*cdf0e10cSrcweir                                 if ( !bModified )
302*cdf0e10cSrcweir                                 {
303*cdf0e10cSrcweir                                     try
304*cdf0e10cSrcweir                                     {
305*cdf0e10cSrcweir                                         xModifiable->setModified( sal_False );
306*cdf0e10cSrcweir                                     }
307*cdf0e10cSrcweir                                     catch( com::sun::star::beans::PropertyVetoException& )
308*cdf0e10cSrcweir                                     {
309*cdf0e10cSrcweir                                     }
310*cdf0e10cSrcweir                                 }
311*cdf0e10cSrcweir                                 eRet = SAVE_CANCELLED;
312*cdf0e10cSrcweir                             }
313*cdf0e10cSrcweir                         }
314*cdf0e10cSrcweir                         break;
315*cdf0e10cSrcweir                     }
316*cdf0e10cSrcweir                 }
317*cdf0e10cSrcweir             }
318*cdf0e10cSrcweir         }
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir     catch( css::uno::RuntimeException& )
321*cdf0e10cSrcweir     {
322*cdf0e10cSrcweir         throw;
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir     catch( uno::Exception& )
325*cdf0e10cSrcweir     {
326*cdf0e10cSrcweir     }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     return eRet;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir sal_Int32 SfxMailModel::GetCount() const
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir     return maAttachedDocuments.size();
334*cdf0e10cSrcweir }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir sal_Bool SfxMailModel::IsEmpty() const
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir     return maAttachedDocuments.empty();
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir SfxMailModel::SaveResult SfxMailModel::SaveDocumentAsFormat(
342*cdf0e10cSrcweir     const rtl::OUString& aSaveFileName,
343*cdf0e10cSrcweir     const css::uno::Reference< css::uno::XInterface >& xFrameOrModel,
344*cdf0e10cSrcweir     const rtl::OUString& rType,
345*cdf0e10cSrcweir     rtl::OUString& rFileNamePath )
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir     SaveResult  eRet( SAVE_ERROR );
348*cdf0e10cSrcweir     bool        bSendAsPDF = (rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN ));
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = ::comphelper::getProcessServiceFactory();
351*cdf0e10cSrcweir     if (!xSMGR.is())
352*cdf0e10cSrcweir         return eRet;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ));
355*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW );
356*cdf0e10cSrcweir     if ( !xModuleManager.is() )
357*cdf0e10cSrcweir         return eRet;
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     rtl::OUString aModule;
360*cdf0e10cSrcweir     try
361*cdf0e10cSrcweir     {
362*cdf0e10cSrcweir          aModule = xModuleManager->identify( xFrameOrModel );
363*cdf0e10cSrcweir     }
364*cdf0e10cSrcweir     catch ( css::uno::RuntimeException& )
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         throw;
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir     catch ( css::uno::Exception& )
369*cdf0e10cSrcweir     {
370*cdf0e10cSrcweir     }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xFrame( xFrameOrModel, css::uno::UNO_QUERY );
373*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xModel( xFrameOrModel, css::uno::UNO_QUERY );
374*cdf0e10cSrcweir     if ( xFrame.is() )
375*cdf0e10cSrcweir     {
376*cdf0e10cSrcweir         css::uno::Reference< css::frame::XController > xController = xFrame->getController();
377*cdf0e10cSrcweir         if ( xController.is() )
378*cdf0e10cSrcweir             xModel = xController->getModel();
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     // We need at least a valid module name and model reference
382*cdf0e10cSrcweir     if (( aModule.getLength() > 0 ) && xModel.is() )
383*cdf0e10cSrcweir     {
384*cdf0e10cSrcweir         bool bModified( false );
385*cdf0e10cSrcweir         bool bHasLocation( false );
386*cdf0e10cSrcweir         bool bStoreTo( false );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY );
389*cdf0e10cSrcweir         css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY );
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir         if ( xModifiable.is() )
392*cdf0e10cSrcweir             bModified = xModifiable->isModified();
393*cdf0e10cSrcweir         if ( xStorable.is() )
394*cdf0e10cSrcweir         {
395*cdf0e10cSrcweir             rtl::OUString aLocation = xStorable->getLocation();
396*cdf0e10cSrcweir             INetURLObject aFileObj( aLocation );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir             bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE );
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir             bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol;
401*cdf0e10cSrcweir             OSL_ASSERT( !bPrivateProtocol );
402*cdf0e10cSrcweir         }
403*cdf0e10cSrcweir         if ( rType.getLength() > 0 )
404*cdf0e10cSrcweir             bStoreTo = true;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir         if ( xStorable.is() )
407*cdf0e10cSrcweir         {
408*cdf0e10cSrcweir             rtl::OUString aFilterName;
409*cdf0e10cSrcweir             rtl::OUString aTypeName( rType );
410*cdf0e10cSrcweir             rtl::OUString aFileName;
411*cdf0e10cSrcweir             rtl::OUString aExtension;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir             css::uno::Reference< css::container::XContainerQuery > xContainerQuery(
414*cdf0e10cSrcweir                 xSMGR->createInstance( rtl::OUString(
415*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))),
416*cdf0e10cSrcweir                     css::uno::UNO_QUERY );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir             if ( bStoreTo )
419*cdf0e10cSrcweir             {
420*cdf0e10cSrcweir                 // Retrieve filter from type
421*cdf0e10cSrcweir                 css::uno::Sequence< css::beans::NamedValue > aQuery( bSendAsPDF ? 3 : 2 );
422*cdf0e10cSrcweir                 aQuery[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ));
423*cdf0e10cSrcweir                 aQuery[0].Value = css::uno::makeAny( aTypeName );
424*cdf0e10cSrcweir                 aQuery[1].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ));
425*cdf0e10cSrcweir                 aQuery[1].Value = css::uno::makeAny( aModule );
426*cdf0e10cSrcweir                 if( bSendAsPDF )
427*cdf0e10cSrcweir                 {
428*cdf0e10cSrcweir                     // #i91419#
429*cdf0e10cSrcweir                     // FIXME: we want just an export filter. However currently we need
430*cdf0e10cSrcweir                     // exact flag value as detailed in the filter configuration to get it
431*cdf0e10cSrcweir                     // this seems to be a bug
432*cdf0e10cSrcweir                     // without flags we get an import filter here, which is also unwanted
433*cdf0e10cSrcweir                     aQuery[2].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" ));
434*cdf0e10cSrcweir                     aQuery[2].Value = css::uno::makeAny( sal_Int32(0x80042) ); // EXPORT ALIEN 3RDPARTY
435*cdf0e10cSrcweir                 }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir                 css::uno::Reference< css::container::XEnumeration > xEnumeration =
438*cdf0e10cSrcweir                     xContainerQuery->createSubSetEnumerationByProperties( aQuery );
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir                 if ( xEnumeration->hasMoreElements() )
441*cdf0e10cSrcweir                 {
442*cdf0e10cSrcweir                     ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() );
443*cdf0e10cSrcweir                     aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
444*cdf0e10cSrcweir                                                 ::rtl::OUString::createFromAscii( "Name" ),
445*cdf0e10cSrcweir                                                 ::rtl::OUString() );
446*cdf0e10cSrcweir                 }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir                 if ( bHasLocation )
449*cdf0e10cSrcweir                 {
450*cdf0e10cSrcweir                     // Retrieve filter from media descriptor
451*cdf0e10cSrcweir                     ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
452*cdf0e10cSrcweir                     rtl::OUString aOrgFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault(
453*cdf0e10cSrcweir                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )),
454*cdf0e10cSrcweir                                     ::rtl::OUString() );
455*cdf0e10cSrcweir                     if ( aOrgFilterName == aFilterName )
456*cdf0e10cSrcweir                     {
457*cdf0e10cSrcweir                         // We should save the document in the original format. Therefore this
458*cdf0e10cSrcweir                         // is not a storeTo operation. To support signing in this case, reset
459*cdf0e10cSrcweir                         // bStoreTo flag.
460*cdf0e10cSrcweir                         bStoreTo = false;
461*cdf0e10cSrcweir                     }
462*cdf0e10cSrcweir                 }
463*cdf0e10cSrcweir             }
464*cdf0e10cSrcweir             else
465*cdf0e10cSrcweir             {
466*cdf0e10cSrcweir                 if ( bHasLocation )
467*cdf0e10cSrcweir                 {
468*cdf0e10cSrcweir                     // Retrieve filter from media descriptor
469*cdf0e10cSrcweir                     ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
470*cdf0e10cSrcweir                     aFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault(
471*cdf0e10cSrcweir                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )),
472*cdf0e10cSrcweir                                     ::rtl::OUString() );
473*cdf0e10cSrcweir                 }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir                 if ( !bHasLocation || ( aFilterName.getLength() == 0 ))
476*cdf0e10cSrcweir                 {
477*cdf0e10cSrcweir                     // Retrieve the user defined default filter
478*cdf0e10cSrcweir                     css::uno::Reference< css::container::XNameAccess > xNameAccess( xModuleManager, css::uno::UNO_QUERY );
479*cdf0e10cSrcweir                     try
480*cdf0e10cSrcweir                     {
481*cdf0e10cSrcweir                         ::comphelper::SequenceAsHashMap aFilterPropsHM( xNameAccess->getByName( aModule ) );
482*cdf0e10cSrcweir                         aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
483*cdf0e10cSrcweir                                                     ::rtl::OUString::createFromAscii( "ooSetupFactoryDefaultFilter" ),
484*cdf0e10cSrcweir                                                     ::rtl::OUString() );
485*cdf0e10cSrcweir                         css::uno::Reference< css::container::XNameAccess > xNameAccess2(
486*cdf0e10cSrcweir                             xContainerQuery, css::uno::UNO_QUERY );
487*cdf0e10cSrcweir                         if ( xNameAccess2.is() )
488*cdf0e10cSrcweir                         {
489*cdf0e10cSrcweir                             ::comphelper::SequenceAsHashMap aFilterPropsHM2( xNameAccess2->getByName( aFilterName ) );
490*cdf0e10cSrcweir                             aTypeName = aFilterPropsHM2.getUnpackedValueOrDefault(
491*cdf0e10cSrcweir                                                         ::rtl::OUString::createFromAscii( "Type" ),
492*cdf0e10cSrcweir                                                         ::rtl::OUString() );
493*cdf0e10cSrcweir                         }
494*cdf0e10cSrcweir                     }
495*cdf0e10cSrcweir                     catch ( css::container::NoSuchElementException& )
496*cdf0e10cSrcweir                     {
497*cdf0e10cSrcweir                     }
498*cdf0e10cSrcweir                     catch ( css::beans::UnknownPropertyException& )
499*cdf0e10cSrcweir                     {
500*cdf0e10cSrcweir                     }
501*cdf0e10cSrcweir                 }
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir             // No filter found => error
505*cdf0e10cSrcweir             // No type and no location => error
506*cdf0e10cSrcweir             if (( aFilterName.getLength() == 0 ) ||
507*cdf0e10cSrcweir                 (( aTypeName.getLength() == 0 ) && !bHasLocation ))
508*cdf0e10cSrcweir                 return eRet;
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir             // Determine filen name and extension
511*cdf0e10cSrcweir             if ( bHasLocation && !bStoreTo )
512*cdf0e10cSrcweir             {
513*cdf0e10cSrcweir                 INetURLObject aFileObj( xStorable->getLocation() );
514*cdf0e10cSrcweir                 aExtension = (rtl::OUString)aFileObj.getExtension();
515*cdf0e10cSrcweir             }
516*cdf0e10cSrcweir             else
517*cdf0e10cSrcweir             {
518*cdf0e10cSrcweir                 css::uno::Reference< container::XNameAccess > xTypeDetection(
519*cdf0e10cSrcweir                     xSMGR->createInstance( ::rtl::OUString(
520*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ))),
521*cdf0e10cSrcweir                     css::uno::UNO_QUERY );
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir                 if ( xTypeDetection.is() )
525*cdf0e10cSrcweir                 {
526*cdf0e10cSrcweir                     try
527*cdf0e10cSrcweir                     {
528*cdf0e10cSrcweir                         ::comphelper::SequenceAsHashMap aTypeNamePropsHM( xTypeDetection->getByName( aTypeName ) );
529*cdf0e10cSrcweir                         uno::Sequence< ::rtl::OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
530*cdf0e10cSrcweir                                                         ::rtl::OUString::createFromAscii( "Extensions" ),
531*cdf0e10cSrcweir                                                         ::uno::Sequence< ::rtl::OUString >() );
532*cdf0e10cSrcweir                         if ( aExtensions.getLength() )
533*cdf0e10cSrcweir                             aExtension = aExtensions[0];
534*cdf0e10cSrcweir                     }
535*cdf0e10cSrcweir                     catch ( css::container::NoSuchElementException& )
536*cdf0e10cSrcweir                     {
537*cdf0e10cSrcweir                     }
538*cdf0e10cSrcweir                 }
539*cdf0e10cSrcweir             }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir             // Use provided save file name. If empty determine file name
542*cdf0e10cSrcweir             aFileName = aSaveFileName;
543*cdf0e10cSrcweir             if ( aFileName.getLength() == 0 )
544*cdf0e10cSrcweir             {
545*cdf0e10cSrcweir                 if ( !bHasLocation )
546*cdf0e10cSrcweir                 {
547*cdf0e10cSrcweir                     // Create a noname file name with the correct extension
548*cdf0e10cSrcweir                     const rtl::OUString aNoNameFileName( RTL_CONSTASCII_USTRINGPARAM( "noname" ));
549*cdf0e10cSrcweir                     aFileName = aNoNameFileName;
550*cdf0e10cSrcweir                 }
551*cdf0e10cSrcweir                 else
552*cdf0e10cSrcweir                 {
553*cdf0e10cSrcweir                     // Determine file name from model
554*cdf0e10cSrcweir                     INetURLObject aFileObj( xStorable->getLocation() );
555*cdf0e10cSrcweir                     aFileName = aFileObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE );
556*cdf0e10cSrcweir                 }
557*cdf0e10cSrcweir             }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir             // No file name => error
560*cdf0e10cSrcweir             if ( aFileName.getLength() == 0 )
561*cdf0e10cSrcweir                 return eRet;
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir             OSL_ASSERT( aFilterName.getLength() > 0 );
564*cdf0e10cSrcweir             OSL_ASSERT( aFileName.getLength() > 0 );
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir             // Creates a temporary directory to store a predefined file into it.
567*cdf0e10cSrcweir             // This makes it possible to store the file for "send document as e-mail"
568*cdf0e10cSrcweir             // with the original file name. We cannot use the original file as
569*cdf0e10cSrcweir             // some mail programs need exclusive access.
570*cdf0e10cSrcweir             ::utl::TempFile aTempDir( NULL, sal_True );
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir             INetURLObject aFilePathObj( aTempDir.GetURL() );
573*cdf0e10cSrcweir             aFilePathObj.insertName( aFileName );
574*cdf0e10cSrcweir             aFilePathObj.setExtension( aExtension );
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir             rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE );
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir             sal_Int32 nNumArgs(0);
579*cdf0e10cSrcweir             const rtl::OUString aPasswordPropName( RTL_CONSTASCII_USTRINGPARAM( "Password" ));
580*cdf0e10cSrcweir             css::uno::Sequence< css::beans::PropertyValue > aArgs( ++nNumArgs );
581*cdf0e10cSrcweir             aArgs[nNumArgs-1].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
582*cdf0e10cSrcweir             aArgs[nNumArgs-1].Value = css::uno::makeAny( aFilterName );
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir             ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
585*cdf0e10cSrcweir             rtl::OUString aPassword = aMediaDescrPropsHM.getUnpackedValueOrDefault(
586*cdf0e10cSrcweir                                             aPasswordPropName,
587*cdf0e10cSrcweir                                             ::rtl::OUString() );
588*cdf0e10cSrcweir             if ( aPassword.getLength() > 0 )
589*cdf0e10cSrcweir             {
590*cdf0e10cSrcweir                 aArgs.realloc( ++nNumArgs );
591*cdf0e10cSrcweir                 aArgs[nNumArgs-1].Name = aPasswordPropName;
592*cdf0e10cSrcweir                 aArgs[nNumArgs-1].Value = css::uno::makeAny( aPassword );
593*cdf0e10cSrcweir             }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir             bool bNeedsPreparation = false;
596*cdf0e10cSrcweir             css::util::URL aPrepareURL;
597*cdf0e10cSrcweir             css::uno::Reference< css::frame::XDispatch > xPrepareDispatch;
598*cdf0e10cSrcweir             css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( xFrame, css::uno::UNO_QUERY );
599*cdf0e10cSrcweir             css::uno::Reference< css::util::XURLTransformer > xURLTransformer(
600*cdf0e10cSrcweir                         xSMGR->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
601*cdf0e10cSrcweir                         css::uno::UNO_QUERY );
602*cdf0e10cSrcweir             if( !bSendAsPDF )
603*cdf0e10cSrcweir             {
604*cdf0e10cSrcweir                 try
605*cdf0e10cSrcweir                 {
606*cdf0e10cSrcweir                     // check if the document needs to be prepared for sending as mail (embedding of links, removal of invisible content)
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir                     if ( xURLTransformer.is() )
609*cdf0e10cSrcweir                     {
610*cdf0e10cSrcweir                         aPrepareURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrepareMailExport" ));
611*cdf0e10cSrcweir                         xURLTransformer->parseStrict( aPrepareURL );
612*cdf0e10cSrcweir                     }
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir                     if ( xDispatchProvider.is() )
615*cdf0e10cSrcweir                     {
616*cdf0e10cSrcweir                         xPrepareDispatch = css::uno::Reference< css::frame::XDispatch >(
617*cdf0e10cSrcweir                             xDispatchProvider->queryDispatch( aPrepareURL, ::rtl::OUString(), 0 ));
618*cdf0e10cSrcweir                         if ( xPrepareDispatch.is() )
619*cdf0e10cSrcweir                         {
620*cdf0e10cSrcweir                                 PrepareListener_Impl* pPrepareListener;
621*cdf0e10cSrcweir                                 uno::Reference< css::frame::XStatusListener > xStatusListener = pPrepareListener = new PrepareListener_Impl;
622*cdf0e10cSrcweir                                 xPrepareDispatch->addStatusListener( xStatusListener, aPrepareURL );
623*cdf0e10cSrcweir                                 bNeedsPreparation = pPrepareListener->IsSet();
624*cdf0e10cSrcweir                                 xPrepareDispatch->removeStatusListener( xStatusListener, aPrepareURL );
625*cdf0e10cSrcweir                         }
626*cdf0e10cSrcweir                     }
627*cdf0e10cSrcweir                 }
628*cdf0e10cSrcweir                 catch ( css::uno::RuntimeException& )
629*cdf0e10cSrcweir                 {
630*cdf0e10cSrcweir                     throw;
631*cdf0e10cSrcweir                 }
632*cdf0e10cSrcweir                 catch ( css::uno::Exception& )
633*cdf0e10cSrcweir                 {
634*cdf0e10cSrcweir                 }
635*cdf0e10cSrcweir             }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir             if ( bModified || !bHasLocation || bStoreTo || bNeedsPreparation )
638*cdf0e10cSrcweir             {
639*cdf0e10cSrcweir                 // Document is modified, is newly created or should be stored in a special format
640*cdf0e10cSrcweir                 try
641*cdf0e10cSrcweir                 {
642*cdf0e10cSrcweir                     if( bNeedsPreparation && xPrepareDispatch.is() )
643*cdf0e10cSrcweir                     {
644*cdf0e10cSrcweir                         if ( xPrepareDispatch.is() )
645*cdf0e10cSrcweir                         {
646*cdf0e10cSrcweir                             try
647*cdf0e10cSrcweir                             {
648*cdf0e10cSrcweir                                 css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs;
649*cdf0e10cSrcweir                                 xPrepareDispatch->dispatch( aPrepareURL, aDispatchArgs );
650*cdf0e10cSrcweir                             }
651*cdf0e10cSrcweir                             catch ( css::uno::RuntimeException& )
652*cdf0e10cSrcweir                             {
653*cdf0e10cSrcweir                                 throw;
654*cdf0e10cSrcweir                             }
655*cdf0e10cSrcweir                             catch ( css::uno::Exception& )
656*cdf0e10cSrcweir                             {
657*cdf0e10cSrcweir                             }
658*cdf0e10cSrcweir                         }
659*cdf0e10cSrcweir                     }
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir                     //check if this is the pdf otput filter (i#64555)
662*cdf0e10cSrcweir                     if( bSendAsPDF )
663*cdf0e10cSrcweir                     {
664*cdf0e10cSrcweir                         SaveResult eShowPDFFilterDialog = ShowFilterOptionsDialog(
665*cdf0e10cSrcweir                                                             xSMGR, xModel, aFilterName, rType, bModified, nNumArgs, aArgs );
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir                         // don't continue on dialog cancel or error
668*cdf0e10cSrcweir                         if ( eShowPDFFilterDialog != SAVE_SUCCESSFULL )
669*cdf0e10cSrcweir                             return eShowPDFFilterDialog;
670*cdf0e10cSrcweir                     }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir                     xStorable->storeToURL( aFileURL, aArgs );
673*cdf0e10cSrcweir                     rFileNamePath = aFileURL;
674*cdf0e10cSrcweir                     eRet = SAVE_SUCCESSFULL;
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir                     if( !bSendAsPDF )
677*cdf0e10cSrcweir                     {
678*cdf0e10cSrcweir                         css::util::URL aURL;
679*cdf0e10cSrcweir                         // #i30432# notify that export is finished - the Writer may want to restore removed content
680*cdf0e10cSrcweir                         if ( xURLTransformer.is() )
681*cdf0e10cSrcweir                         {
682*cdf0e10cSrcweir                             aURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:MailExportFinished" ));
683*cdf0e10cSrcweir                             xURLTransformer->parseStrict( aURL );
684*cdf0e10cSrcweir                         }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir                         if ( xDispatchProvider.is() )
687*cdf0e10cSrcweir                         {
688*cdf0e10cSrcweir                             css::uno::Reference< css::frame::XDispatch > xDispatch = css::uno::Reference< css::frame::XDispatch >(
689*cdf0e10cSrcweir                                 xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 ));
690*cdf0e10cSrcweir                             if ( xDispatch.is() )
691*cdf0e10cSrcweir                             {
692*cdf0e10cSrcweir                                 try
693*cdf0e10cSrcweir                                 {
694*cdf0e10cSrcweir                                     css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs;
695*cdf0e10cSrcweir                                     xDispatch->dispatch( aURL, aDispatchArgs );
696*cdf0e10cSrcweir                                 }
697*cdf0e10cSrcweir                                 catch ( css::uno::RuntimeException& )
698*cdf0e10cSrcweir                                 {
699*cdf0e10cSrcweir                                     throw;
700*cdf0e10cSrcweir                                 }
701*cdf0e10cSrcweir                                 catch ( css::uno::Exception& )
702*cdf0e10cSrcweir                                 {
703*cdf0e10cSrcweir                                 }
704*cdf0e10cSrcweir                             }
705*cdf0e10cSrcweir                         }
706*cdf0e10cSrcweir                     }
707*cdf0e10cSrcweir                     // If the model is not modified, it could be modified by the dispatch calls.
708*cdf0e10cSrcweir                     // Therefore set back to modified = false. This should not hurt if we call
709*cdf0e10cSrcweir                     // on a non-modified model.
710*cdf0e10cSrcweir                     if ( !bModified )
711*cdf0e10cSrcweir                     {
712*cdf0e10cSrcweir                         try
713*cdf0e10cSrcweir                         {
714*cdf0e10cSrcweir                             xModifiable->setModified( sal_False );
715*cdf0e10cSrcweir                         }
716*cdf0e10cSrcweir                         catch( com::sun::star::beans::PropertyVetoException& )
717*cdf0e10cSrcweir                         {
718*cdf0e10cSrcweir                         }
719*cdf0e10cSrcweir                     }
720*cdf0e10cSrcweir                 }
721*cdf0e10cSrcweir                 catch ( com::sun::star::io::IOException& )
722*cdf0e10cSrcweir                 {
723*cdf0e10cSrcweir                     eRet = SAVE_ERROR;
724*cdf0e10cSrcweir                 }
725*cdf0e10cSrcweir             }
726*cdf0e10cSrcweir             else
727*cdf0e10cSrcweir             {
728*cdf0e10cSrcweir                 // We need 1:1 copy of the document to preserve an added signature.
729*cdf0e10cSrcweir                 aArgs.realloc( ++nNumArgs );
730*cdf0e10cSrcweir                 aArgs[nNumArgs-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyStreamIfPossible" ) );
731*cdf0e10cSrcweir                 aArgs[nNumArgs-1].Value = css::uno::makeAny( (sal_Bool)sal_True );
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir 				try
734*cdf0e10cSrcweir 				{
735*cdf0e10cSrcweir                     xStorable->storeToURL( aFileURL, aArgs );
736*cdf0e10cSrcweir                     rFileNamePath = aFileURL;
737*cdf0e10cSrcweir                     eRet = SAVE_SUCCESSFULL;
738*cdf0e10cSrcweir 				}
739*cdf0e10cSrcweir                 catch ( com::sun::star::io::IOException& )
740*cdf0e10cSrcweir                 {
741*cdf0e10cSrcweir                     eRet = SAVE_ERROR;
742*cdf0e10cSrcweir                 }
743*cdf0e10cSrcweir             }
744*cdf0e10cSrcweir         }
745*cdf0e10cSrcweir     }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     return eRet;
748*cdf0e10cSrcweir }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir SfxMailModel::SfxMailModel() :
751*cdf0e10cSrcweir 	mpToList	( NULL ),
752*cdf0e10cSrcweir 	mpCcList	( NULL ),
753*cdf0e10cSrcweir 	mpBccList	( NULL ),
754*cdf0e10cSrcweir 	mePriority	( PRIO_NORMAL ),
755*cdf0e10cSrcweir 	mbLoadDone	( sal_True )
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir }
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir SfxMailModel::~SfxMailModel()
760*cdf0e10cSrcweir {
761*cdf0e10cSrcweir 	ClearList( mpToList );
762*cdf0e10cSrcweir 	delete mpToList;
763*cdf0e10cSrcweir 	ClearList( mpCcList );
764*cdf0e10cSrcweir 	delete mpCcList;
765*cdf0e10cSrcweir 	ClearList( mpBccList );
766*cdf0e10cSrcweir 	delete mpBccList;
767*cdf0e10cSrcweir }
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir void SfxMailModel::AddAddress( const String& rAddress, AddressRole eRole )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir 	// don't add a empty address
772*cdf0e10cSrcweir 	if ( rAddress.Len() > 0 )
773*cdf0e10cSrcweir 	{
774*cdf0e10cSrcweir 		AddressList_Impl* pList = NULL;
775*cdf0e10cSrcweir 		if ( ROLE_TO == eRole )
776*cdf0e10cSrcweir 		{
777*cdf0e10cSrcweir 			if ( !mpToList )
778*cdf0e10cSrcweir 				// create the list
779*cdf0e10cSrcweir 				mpToList = new AddressList_Impl;
780*cdf0e10cSrcweir 			pList = mpToList;
781*cdf0e10cSrcweir 		}
782*cdf0e10cSrcweir 		else if ( ROLE_CC == eRole )
783*cdf0e10cSrcweir 		{
784*cdf0e10cSrcweir 			if ( !mpCcList )
785*cdf0e10cSrcweir 				// create the list
786*cdf0e10cSrcweir 				mpCcList = new AddressList_Impl;
787*cdf0e10cSrcweir 			pList = mpCcList;
788*cdf0e10cSrcweir 		}
789*cdf0e10cSrcweir 		else if ( ROLE_BCC == eRole )
790*cdf0e10cSrcweir 		{
791*cdf0e10cSrcweir 			if ( !mpBccList )
792*cdf0e10cSrcweir 				// create the list
793*cdf0e10cSrcweir 				mpBccList = new AddressList_Impl;
794*cdf0e10cSrcweir 			pList = mpBccList;
795*cdf0e10cSrcweir 		}
796*cdf0e10cSrcweir 		else
797*cdf0e10cSrcweir 		{
798*cdf0e10cSrcweir 			DBG_ERRORFILE( "invalid address role" );
799*cdf0e10cSrcweir 		}
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 		if ( pList )
802*cdf0e10cSrcweir 		{
803*cdf0e10cSrcweir 			// add address to list
804*cdf0e10cSrcweir 			AddressItemPtr_Impl pAddress = new String( rAddress );
805*cdf0e10cSrcweir 			pList->Insert( pAddress, LIST_APPEND );
806*cdf0e10cSrcweir 		}
807*cdf0e10cSrcweir 	}
808*cdf0e10cSrcweir }
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::AttachDocument(
811*cdf0e10cSrcweir     const ::rtl::OUString& sDocumentType,
812*cdf0e10cSrcweir     const css::uno::Reference< css::uno::XInterface >& xFrameOrModel,
813*cdf0e10cSrcweir     const ::rtl::OUString& sAttachmentTitle )
814*cdf0e10cSrcweir {
815*cdf0e10cSrcweir     rtl::OUString sFileName;
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir     SaveResult eSaveResult = SaveDocumentAsFormat( sAttachmentTitle, xFrameOrModel, sDocumentType, sFileName );
818*cdf0e10cSrcweir     if ( eSaveResult == SAVE_SUCCESSFULL && ( sFileName.getLength() > 0 ) )
819*cdf0e10cSrcweir         maAttachedDocuments.push_back(sFileName);
820*cdf0e10cSrcweir     return eSaveResult == SAVE_SUCCESSFULL ? SEND_MAIL_OK : SEND_MAIL_ERROR;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css::frame::XFrame >& xFrame )
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir 	OSL_ENSURE(!maAttachedDocuments.empty(),"No document added!");
826*cdf0e10cSrcweir 	SendMailResult	eResult = SEND_MAIL_ERROR;
827*cdf0e10cSrcweir     if ( !maAttachedDocuments.empty() )
828*cdf0e10cSrcweir 	{
829*cdf0e10cSrcweir 	    css::uno::Reference < XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory();
830*cdf0e10cSrcweir 	    if ( xMgr.is() )
831*cdf0e10cSrcweir 	    {
832*cdf0e10cSrcweir 		    css::uno::Reference< XSimpleMailClientSupplier >	xSimpleMailClientSupplier;
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir             // Prefer the SimpleSystemMail service if available
835*cdf0e10cSrcweir             xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
836*cdf0e10cSrcweir                 xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleSystemMail" ))),
837*cdf0e10cSrcweir                 UNO_QUERY );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir             if ( ! xSimpleMailClientSupplier.is() )
840*cdf0e10cSrcweir             {
841*cdf0e10cSrcweir                 xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
842*cdf0e10cSrcweir                     xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleCommandMail" ))),
843*cdf0e10cSrcweir                     UNO_QUERY );
844*cdf0e10cSrcweir             }
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 		    if ( xSimpleMailClientSupplier.is() )
847*cdf0e10cSrcweir 		    {
848*cdf0e10cSrcweir 			    css::uno::Reference< XSimpleMailClient > xSimpleMailClient = xSimpleMailClientSupplier->querySimpleMailClient();
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 			    if ( !xSimpleMailClient.is() )
851*cdf0e10cSrcweir 			    {
852*cdf0e10cSrcweir 				    // no mail client support => message box!
853*cdf0e10cSrcweir 				    return SEND_MAIL_ERROR;
854*cdf0e10cSrcweir 			    }
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 			    // we have a simple mail client
857*cdf0e10cSrcweir 			    css::uno::Reference< XSimpleMailMessage > xSimpleMailMessage = xSimpleMailClient->createSimpleMailMessage();
858*cdf0e10cSrcweir 			    if ( xSimpleMailMessage.is() )
859*cdf0e10cSrcweir 			    {
860*cdf0e10cSrcweir 				    sal_Int32 nSendFlags = SimpleMailClientFlags::DEFAULTS;
861*cdf0e10cSrcweir 				    if ( maFromAddress.Len() == 0 )
862*cdf0e10cSrcweir 				    {
863*cdf0e10cSrcweir 					    // from address not set, try figure out users e-mail address
864*cdf0e10cSrcweir 					    CreateFromAddress_Impl( maFromAddress );
865*cdf0e10cSrcweir 				    }
866*cdf0e10cSrcweir 				    xSimpleMailMessage->setOriginator( maFromAddress );
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 				    sal_Int32 nToCount		= mpToList ? mpToList->Count() : 0;
869*cdf0e10cSrcweir 				    sal_Int32 nCcCount		= mpCcList ? mpCcList->Count() : 0;
870*cdf0e10cSrcweir 				    sal_Int32 nCcSeqCount	= nCcCount;
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 				    // set recipient (only one) for this simple mail server!!
873*cdf0e10cSrcweir 				    if ( nToCount > 1 )
874*cdf0e10cSrcweir 				    {
875*cdf0e10cSrcweir 					    nCcSeqCount = nToCount - 1 + nCcCount;
876*cdf0e10cSrcweir 					    xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
877*cdf0e10cSrcweir 					    nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
878*cdf0e10cSrcweir 				    }
879*cdf0e10cSrcweir 				    else if ( nToCount == 1 )
880*cdf0e10cSrcweir 				    {
881*cdf0e10cSrcweir 					    xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
882*cdf0e10cSrcweir 					    nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
883*cdf0e10cSrcweir 				    }
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 				    // all other recipient must be handled with CC recipients!
886*cdf0e10cSrcweir 				    if ( nCcSeqCount > 0 )
887*cdf0e10cSrcweir 				    {
888*cdf0e10cSrcweir 					    sal_Int32				nIndex = 0;
889*cdf0e10cSrcweir 					    Sequence< OUString >	aCcRecipientSeq;
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir 					    aCcRecipientSeq.realloc( nCcSeqCount );
892*cdf0e10cSrcweir 					    if ( nCcSeqCount > nCcCount )
893*cdf0e10cSrcweir     				    {
894*cdf0e10cSrcweir 						    for ( sal_Int32 i = 1; i < nToCount; ++i )
895*cdf0e10cSrcweir 						    {
896*cdf0e10cSrcweir 							    aCcRecipientSeq[nIndex++] = *mpToList->GetObject(i);
897*cdf0e10cSrcweir 						    }
898*cdf0e10cSrcweir 					    }
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir 					    for ( sal_Int32 i = 0; i < nCcCount; i++ )
901*cdf0e10cSrcweir 					    {
902*cdf0e10cSrcweir 						    aCcRecipientSeq[nIndex++] = *mpCcList->GetObject(i);
903*cdf0e10cSrcweir 					    }
904*cdf0e10cSrcweir 					    xSimpleMailMessage->setCcRecipient( aCcRecipientSeq );
905*cdf0e10cSrcweir 				    }
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir 				    sal_Int32 nBccCount = mpBccList ? mpBccList->Count() : 0;
908*cdf0e10cSrcweir 				    if ( nBccCount > 0 )
909*cdf0e10cSrcweir 				    {
910*cdf0e10cSrcweir 	    			    Sequence< OUString > aBccRecipientSeq( nBccCount );
911*cdf0e10cSrcweir 					    for ( sal_Int32 i = 0; i < nBccCount; ++i )
912*cdf0e10cSrcweir 					    {
913*cdf0e10cSrcweir 						    aBccRecipientSeq[i] = *mpBccList->GetObject(i);
914*cdf0e10cSrcweir 					    }
915*cdf0e10cSrcweir 					    xSimpleMailMessage->setBccRecipient( aBccRecipientSeq );
916*cdf0e10cSrcweir 				    }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir 					Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size());
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir 				    xSimpleMailMessage->setSubject( maSubject );
921*cdf0e10cSrcweir 				    xSimpleMailMessage->setAttachement( aAttachmentSeq );
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir 	                sal_Bool bSend( sal_False );
924*cdf0e10cSrcweir                     try
925*cdf0e10cSrcweir 	                {
926*cdf0e10cSrcweir 		                xSimpleMailClient->sendSimpleMailMessage( xSimpleMailMessage, nSendFlags );
927*cdf0e10cSrcweir 		                bSend = sal_True;
928*cdf0e10cSrcweir 	                }
929*cdf0e10cSrcweir 	                catch ( IllegalArgumentException& )
930*cdf0e10cSrcweir 	                {
931*cdf0e10cSrcweir 	                }
932*cdf0e10cSrcweir 	                catch ( Exception& )
933*cdf0e10cSrcweir 	                {
934*cdf0e10cSrcweir 	                }
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 	                if ( bSend == sal_False )
937*cdf0e10cSrcweir 	                {
938*cdf0e10cSrcweir                         css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow();
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir                         ::vos::OGuard aGuard( Application::GetSolarMutex() );
941*cdf0e10cSrcweir                         Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow );
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir                         ErrorBox aBox( pParentWindow, SfxResId( RID_ERRBOX_MAIL_CONFIG ));
944*cdf0e10cSrcweir 		                aBox.Execute();
945*cdf0e10cSrcweir                         eResult = SEND_MAIL_CANCELLED;
946*cdf0e10cSrcweir 	                }
947*cdf0e10cSrcweir                     else
948*cdf0e10cSrcweir 					    eResult = SEND_MAIL_OK;
949*cdf0e10cSrcweir 			    }
950*cdf0e10cSrcweir 		    }
951*cdf0e10cSrcweir 	    }
952*cdf0e10cSrcweir     }
953*cdf0e10cSrcweir 	else
954*cdf0e10cSrcweir 		eResult = SEND_MAIL_CANCELLED;
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 	return eResult;
957*cdf0e10cSrcweir }
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::SaveAndSend( const css::uno::Reference< css::frame::XFrame >& xFrame, const rtl::OUString& rTypeName )
960*cdf0e10cSrcweir {
961*cdf0e10cSrcweir 	SaveResult		eSaveResult;
962*cdf0e10cSrcweir 	SendMailResult	eResult = SEND_MAIL_ERROR;
963*cdf0e10cSrcweir     rtl::OUString   aFileName;
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir     eSaveResult = SaveDocumentAsFormat( rtl::OUString(), xFrame, rTypeName, aFileName );
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir     if ( eSaveResult == SAVE_SUCCESSFULL )
968*cdf0e10cSrcweir     {
969*cdf0e10cSrcweir         maAttachedDocuments.push_back( aFileName );
970*cdf0e10cSrcweir         return Send( xFrame );
971*cdf0e10cSrcweir     }
972*cdf0e10cSrcweir 	else if ( eSaveResult == SAVE_CANCELLED )
973*cdf0e10cSrcweir 		eResult = SEND_MAIL_CANCELLED;
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir 	return eResult;
976*cdf0e10cSrcweir }
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir // functions -------------------------------------------------------------
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir sal_Bool CreateFromAddress_Impl( String& rFrom )
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir /*	[Beschreibung]
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir 	Diese Funktion versucht mit Hilfe des IniManagers eine From-Adresse
985*cdf0e10cSrcweir 	zu erzeugen. daf"ur werden die Felder 'Vorname', 'Name' und 'EMail'
986*cdf0e10cSrcweir 	aus der Applikations-Ini-Datei ausgelesen. Sollten diese Felder
987*cdf0e10cSrcweir 	nicht gesetzt sein, wird FALSE zur"uckgegeben.
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir 	[R"uckgabewert]
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir 	sal_True:	Adresse konnte erzeugt werden.
992*cdf0e10cSrcweir 	sal_False:	Adresse konnte nicht erzeugt werden.
993*cdf0e10cSrcweir */
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir {
996*cdf0e10cSrcweir 	SvtUserOptions aUserCFG;
997*cdf0e10cSrcweir 	String aName		= aUserCFG.GetLastName	();
998*cdf0e10cSrcweir 	String aFirstName	= aUserCFG.GetFirstName	();
999*cdf0e10cSrcweir 	if ( aFirstName.Len() || aName.Len() )
1000*cdf0e10cSrcweir 	{
1001*cdf0e10cSrcweir 		if ( aFirstName.Len() )
1002*cdf0e10cSrcweir 		{
1003*cdf0e10cSrcweir 			rFrom = TRIM( aFirstName );
1004*cdf0e10cSrcweir 
1005*cdf0e10cSrcweir 			if ( aName.Len() )
1006*cdf0e10cSrcweir 				rFrom += ' ';
1007*cdf0e10cSrcweir 		}
1008*cdf0e10cSrcweir 		rFrom += TRIM( aName );
1009*cdf0e10cSrcweir 		// unerlaubte Zeichen entfernen
1010*cdf0e10cSrcweir 		rFrom.EraseAllChars( '<' );
1011*cdf0e10cSrcweir 		rFrom.EraseAllChars( '>' );
1012*cdf0e10cSrcweir 		rFrom.EraseAllChars( '@' );
1013*cdf0e10cSrcweir 	}
1014*cdf0e10cSrcweir 	String aEmailName = aUserCFG.GetEmail();
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir     // unerlaubte Zeichen entfernen
1017*cdf0e10cSrcweir 	aEmailName.EraseAllChars( '<' );
1018*cdf0e10cSrcweir 	aEmailName.EraseAllChars( '>' );
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir 	if ( aEmailName.Len() )
1021*cdf0e10cSrcweir 	{
1022*cdf0e10cSrcweir 		if ( rFrom.Len() )
1023*cdf0e10cSrcweir 			rFrom += ' ';
1024*cdf0e10cSrcweir 		( ( rFrom += '<' ) += TRIM( aEmailName ) ) += '>';
1025*cdf0e10cSrcweir 	}
1026*cdf0e10cSrcweir 	else
1027*cdf0e10cSrcweir 		rFrom.Erase();
1028*cdf0e10cSrcweir 	return ( rFrom.Len() > 0 );
1029*cdf0e10cSrcweir }
1030