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