LCOV - code coverage report
Current view: top level - sfx2/source/dialog - mailmodel.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 391 0.3 %
Date: 2014-04-14 Functions: 2 18 11.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10