mailmodel.cxx (d119d52d) mailmodel.cxx (ae77b8ca)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 18 unchanged lines hidden (view full) ---

27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/beans/XPropertyAccess.hpp>
29#include <com/sun/star/frame/XFrame.hpp>
30#include <com/sun/star/frame/XModel.hpp>
31#include <com/sun/star/lang/XMultiServiceFactory.hpp>
32#include <com/sun/star/ucb/CommandAbortedException.hpp>
33#include <com/sun/star/uno/Reference.h>
34#include <com/sun/star/util/XURLTransformer.hpp>
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 18 unchanged lines hidden (view full) ---

27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/beans/XPropertyAccess.hpp>
29#include <com/sun/star/frame/XFrame.hpp>
30#include <com/sun/star/frame/XModel.hpp>
31#include <com/sun/star/lang/XMultiServiceFactory.hpp>
32#include <com/sun/star/ucb/CommandAbortedException.hpp>
33#include <com/sun/star/uno/Reference.h>
34#include <com/sun/star/util/XURLTransformer.hpp>
35#include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
36#include <com/sun/star/system/SimpleMailClientFlags.hpp>
35#include <com/sun/star/system/SystemMailProvider.hpp>
36#include <com/sun/star/system/MailClientFlags.hpp>
37#include <com/sun/star/embed/XStorage.hpp>
38#include <com/sun/star/embed/ElementModes.hpp>
39#include <com/sun/star/embed/XTransactedObject.hpp>
40#include <com/sun/star/container/XContainerQuery.hpp>
41#include <com/sun/star/util/XModifiable.hpp>
42#include <com/sun/star/frame/XModuleManager.hpp>
43#include <com/sun/star/frame/XStorable.hpp>
44#include <com/sun/star/beans/XPropertySet.hpp>

--- 37 unchanged lines hidden (view full) ---

82using namespace ::com::sun::star;
83using namespace ::com::sun::star::beans;
84using namespace ::com::sun::star::frame;
85using namespace ::com::sun::star::io;
86using namespace ::com::sun::star::lang;
87using namespace ::com::sun::star::ucb;
88using namespace ::com::sun::star::uno;
89using namespace ::com::sun::star::util;
37#include <com/sun/star/embed/XStorage.hpp>
38#include <com/sun/star/embed/ElementModes.hpp>
39#include <com/sun/star/embed/XTransactedObject.hpp>
40#include <com/sun/star/container/XContainerQuery.hpp>
41#include <com/sun/star/util/XModifiable.hpp>
42#include <com/sun/star/frame/XModuleManager.hpp>
43#include <com/sun/star/frame/XStorable.hpp>
44#include <com/sun/star/beans/XPropertySet.hpp>

--- 37 unchanged lines hidden (view full) ---

82using namespace ::com::sun::star;
83using namespace ::com::sun::star::beans;
84using namespace ::com::sun::star::frame;
85using namespace ::com::sun::star::io;
86using namespace ::com::sun::star::lang;
87using namespace ::com::sun::star::ucb;
88using namespace ::com::sun::star::uno;
89using namespace ::com::sun::star::util;
90using namespace ::com::sun::star::system;
91using namespace ::rtl;
92
90
91using ::com::sun::star::system::SystemMailProvider;
92using ::com::sun::star::system::XMailClient;
93using ::com::sun::star::system::XMailMessage;
94using ::com::sun::star::system::XSystemMailProvider;
95using rtl::OUString;
96
97namespace MailClientFlags = ::com::sun::star::system::MailClientFlags;
93namespace css = ::com::sun::star;
98namespace css = ::com::sun::star;
99
100
94// - class PrepareListener_Impl ------------------------------------------
95class PrepareListener_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
96{
97 bool m_bState;
98public:
99 PrepareListener_Impl();
100 virtual ~PrepareListener_Impl();
101

--- 715 unchanged lines hidden (view full) ---

817}
818
819SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css::frame::XFrame >& xFrame )
820{
821 OSL_ENSURE(!maAttachedDocuments.empty(),"No document added!");
822 SendMailResult eResult = SEND_MAIL_ERROR;
823 if ( !maAttachedDocuments.empty() )
824 {
101// - class PrepareListener_Impl ------------------------------------------
102class PrepareListener_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
103{
104 bool m_bState;
105public:
106 PrepareListener_Impl();
107 virtual ~PrepareListener_Impl();
108

--- 715 unchanged lines hidden (view full) ---

824}
825
826SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css::frame::XFrame >& xFrame )
827{
828 OSL_ENSURE(!maAttachedDocuments.empty(),"No document added!");
829 SendMailResult eResult = SEND_MAIL_ERROR;
830 if ( !maAttachedDocuments.empty() )
831 {
825 css::uno::Reference < XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory();
826 if ( xMgr.is() )
832 css::uno::Reference < XComponentContext > xContext = ::comphelper::getProcessComponentContext();
833 if ( xContext.is() )
827 {
834 {
828 css::uno::Reference< XSimpleMailClientSupplier > xSimpleMailClientSupplier;
835 css::uno::Reference< XSystemMailProvider > xSystemMailProvider( SystemMailProvider::create( xContext ) );
829
836
830 // Prefer the SimpleSystemMail service if available
831 xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
832 xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleSystemMail" ))),
833 UNO_QUERY );
834
835 if ( ! xSimpleMailClientSupplier.is() )
836 {
837 xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
838 xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleCommandMail" ))),
839 UNO_QUERY );
840 }
841
842 if ( xSimpleMailClientSupplier.is() )
837 if ( xSystemMailProvider.is() )
843 {
838 {
844 css::uno::Reference< XSimpleMailClient > xSimpleMailClient = xSimpleMailClientSupplier->querySimpleMailClient();
839 css::uno::Reference< XMailClient > xMailClient = xSystemMailProvider->queryMailClient();
845
840
846 if ( !xSimpleMailClient.is() )
841 if ( !xMailClient.is() )
847 {
848 // no mail client support => message box!
849 return SEND_MAIL_ERROR;
850 }
851
852 // we have a simple mail client
842 {
843 // no mail client support => message box!
844 return SEND_MAIL_ERROR;
845 }
846
847 // we have a simple mail client
853 css::uno::Reference< XSimpleMailMessage > xSimpleMailMessage = xSimpleMailClient->createSimpleMailMessage();
854 if ( xSimpleMailMessage.is() )
848 css::uno::Reference< XMailMessage > xMailMessage = xMailClient->createMailMessage();
849 if ( xMailMessage.is() )
855 {
850 {
856 sal_Int32 nSendFlags = SimpleMailClientFlags::DEFAULTS;
851 sal_Int32 nSendFlags = MailClientFlags::DEFAULTS;
857 if ( maFromAddress.Len() == 0 )
858 {
859 // from address not set, try figure out users e-mail address
860 CreateFromAddress_Impl( maFromAddress );
861 }
852 if ( maFromAddress.Len() == 0 )
853 {
854 // from address not set, try figure out users e-mail address
855 CreateFromAddress_Impl( maFromAddress );
856 }
862 xSimpleMailMessage->setOriginator( maFromAddress );
857 xMailMessage->setOriginator( maFromAddress );
863
864 sal_Int32 nToCount = mpToList ? mpToList->Count() : 0;
865 sal_Int32 nCcCount = mpCcList ? mpCcList->Count() : 0;
866 sal_Int32 nCcSeqCount = nCcCount;
867
868 // set recipient (only one) for this simple mail server!!
869 if ( nToCount > 1 )
870 {
871 nCcSeqCount = nToCount - 1 + nCcCount;
858
859 sal_Int32 nToCount = mpToList ? mpToList->Count() : 0;
860 sal_Int32 nCcCount = mpCcList ? mpCcList->Count() : 0;
861 sal_Int32 nCcSeqCount = nCcCount;
862
863 // set recipient (only one) for this simple mail server!!
864 if ( nToCount > 1 )
865 {
866 nCcSeqCount = nToCount - 1 + nCcCount;
872 xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
873 nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
867 xMailMessage->setRecipient( *mpToList->GetObject( 0 ));
868 nSendFlags = MailClientFlags::NO_USER_INTERFACE;
874 }
875 else if ( nToCount == 1 )
876 {
869 }
870 else if ( nToCount == 1 )
871 {
877 xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
878 nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
872 xMailMessage->setRecipient( *mpToList->GetObject( 0 ));
873 nSendFlags = MailClientFlags::NO_USER_INTERFACE;
879 }
880
881 // all other recipient must be handled with CC recipients!
882 if ( nCcSeqCount > 0 )
883 {
884 sal_Int32 nIndex = 0;
885 Sequence< OUString > aCcRecipientSeq;
886

--- 5 unchanged lines hidden (view full) ---

892 aCcRecipientSeq[nIndex++] = *mpToList->GetObject(i);
893 }
894 }
895
896 for ( sal_Int32 i = 0; i < nCcCount; i++ )
897 {
898 aCcRecipientSeq[nIndex++] = *mpCcList->GetObject(i);
899 }
874 }
875
876 // all other recipient must be handled with CC recipients!
877 if ( nCcSeqCount > 0 )
878 {
879 sal_Int32 nIndex = 0;
880 Sequence< OUString > aCcRecipientSeq;
881

--- 5 unchanged lines hidden (view full) ---

887 aCcRecipientSeq[nIndex++] = *mpToList->GetObject(i);
888 }
889 }
890
891 for ( sal_Int32 i = 0; i < nCcCount; i++ )
892 {
893 aCcRecipientSeq[nIndex++] = *mpCcList->GetObject(i);
894 }
900 xSimpleMailMessage->setCcRecipient( aCcRecipientSeq );
895 xMailMessage->setCcRecipient( aCcRecipientSeq );
901 }
902
903 sal_Int32 nBccCount = mpBccList ? mpBccList->Count() : 0;
904 if ( nBccCount > 0 )
905 {
906 Sequence< OUString > aBccRecipientSeq( nBccCount );
907 for ( sal_Int32 i = 0; i < nBccCount; ++i )
908 {
909 aBccRecipientSeq[i] = *mpBccList->GetObject(i);
910 }
896 }
897
898 sal_Int32 nBccCount = mpBccList ? mpBccList->Count() : 0;
899 if ( nBccCount > 0 )
900 {
901 Sequence< OUString > aBccRecipientSeq( nBccCount );
902 for ( sal_Int32 i = 0; i < nBccCount; ++i )
903 {
904 aBccRecipientSeq[i] = *mpBccList->GetObject(i);
905 }
911 xSimpleMailMessage->setBccRecipient( aBccRecipientSeq );
906 xMailMessage->setBccRecipient( aBccRecipientSeq );
912 }
913
914 Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size());
915
907 }
908
909 Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size());
910
916 xSimpleMailMessage->setSubject( maSubject );
917 xSimpleMailMessage->setAttachement( aAttachmentSeq );
911 xMailMessage->setSubject( maSubject );
912 xMailMessage->setAttachement( aAttachmentSeq );
918
919 sal_Bool bSend( sal_False );
920 try
921 {
913
914 sal_Bool bSend( sal_False );
915 try
916 {
922 xSimpleMailClient->sendSimpleMailMessage( xSimpleMailMessage, nSendFlags );
917 xMailClient->sendMailMessage( xMailMessage, nSendFlags );
923 bSend = sal_True;
924 }
925 catch ( IllegalArgumentException& )
926 {
927 }
928 catch ( Exception& )
929 {
930 }

--- 95 unchanged lines hidden ---
918 bSend = sal_True;
919 }
920 catch ( IllegalArgumentException& )
921 {
922 }
923 catch ( Exception& )
924 {
925 }

--- 95 unchanged lines hidden ---