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