1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailmergehelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <swtypes.hxx>
34 #include <mailmergehelper.hxx>
35 #include <svtools/stdctrl.hxx>
36 #include <mmconfigitem.hxx>
40 #include <sfx2/filedlghelper.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/fcontnr.hxx>
44 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
45 #include <com/sun/star/sdb/XColumn.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
48 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
49 #include "com/sun/star/mail/MailServiceProvider.hpp"
50 #include "com/sun/star/mail/XSmtpService.hpp"
51 #include <comphelper/processfactory.hxx>
52 #include <vcl/msgbox.hxx>
54 #include <sfx2/passwd.hxx>
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::container
;
62 using namespace ::com::sun::star::sdb
;
63 using namespace ::com::sun::star::sdbc
;
64 using namespace ::com::sun::star::sdbcx
;
68 //using ::rtl::OUString;
70 namespace SwMailMergeHelper
73 /*-- 14.06.2004 12:29:19---------------------------------------------------
75 -----------------------------------------------------------------------*/
76 String
CallSaveAsDialog(String
& rFilter
)
79 String
sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName()));
80 ::sfx2::FileDialogHelper
aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
,
85 nRet
= aDialog
.Execute();
86 if(ERRCODE_NONE
== nRet
)
88 uno::Reference
< ui::dialogs::XFilePicker
> xFP
= aDialog
.GetFilePicker();
89 sRet
= xFP
->getFiles().getConstArray()[0];
90 rFilter
= aDialog
.GetRealFilter();
94 /*-- 20.08.2004 09:39:18---------------------------------------------------
95 simple address check: check for '@'
96 for at least one '.' after the '@'
97 and for at least to characters before and after the dot
98 -----------------------------------------------------------------------*/
99 bool CheckMailAddress( const ::rtl::OUString
& rMailAddress
)
101 String
sAddress(rMailAddress
);
102 if(!(sAddress
.GetTokenCount('@') == 2))
104 sAddress
= sAddress
.GetToken(1, '@');
105 if(sAddress
.GetTokenCount('.') < 2)
107 if(sAddress
.GetToken( 0, '.').Len() < 2 || sAddress
.GetToken( 1, '.').Len() < 2)
112 /*-- 28.12.2004 10:16:02---------------------------------------------------
114 -----------------------------------------------------------------------*/
115 uno::Reference
< mail::XSmtpService
> ConnectToSmtpServer(
116 SwMailMergeConfigItem
& rConfigItem
,
117 uno::Reference
< mail::XMailService
>& rxInMailService
,
118 const String
& rInMailServerPassword
,
119 const String
& rOutMailServerPassword
,
120 Window
* pDialogParentWindow
)
122 uno::Reference
< mail::XSmtpService
> xSmtpServer
;
123 uno::Reference
< lang::XMultiServiceFactory
> rMgr
= ::comphelper::getProcessServiceFactory();
127 uno::Reference
< mail::XMailServiceProvider
> xMailServiceProvider
=
128 mail::MailServiceProvider::create(getCurrentCmpCtx(rMgr
));
129 xSmtpServer
= uno::Reference
< mail::XSmtpService
> (
130 xMailServiceProvider
->create(
131 mail::MailServiceType_SMTP
134 uno::Reference
< mail::XConnectionListener
> xConnectionListener(new SwConnectionListener());
136 if(rConfigItem
.IsAuthentication() && rConfigItem
.IsSMTPAfterPOP())
138 uno::Reference
< mail::XMailService
> xInMailService
=
139 xMailServiceProvider
->create(
140 rConfigItem
.IsInServerPOP() ?
141 mail::MailServiceType_POP3
: mail::MailServiceType_IMAP
);
142 //authenticate at the POP or IMAP server first
143 String sPasswd
= rConfigItem
.GetInServerPassword();
144 if(rInMailServerPassword
.Len())
145 sPasswd
= rInMailServerPassword
;
146 uno::Reference
<mail::XAuthenticator
> xAuthenticator
=
148 rConfigItem
.GetInServerUserName(),
150 pDialogParentWindow
);
152 xInMailService
->addConnectionListener(xConnectionListener
);
154 uno::Reference
< uno::XCurrentContext
> xConnectionContext
=
155 new SwConnectionContext(
156 rConfigItem
.GetInServerName(),
157 rConfigItem
.GetInServerPort(),
158 ::rtl::OUString::createFromAscii( "Insecure" ));
159 xInMailService
->connect(xConnectionContext
, xAuthenticator
);
160 rxInMailService
= xInMailService
;
162 uno::Reference
< mail::XAuthenticator
> xAuthenticator
;
163 if(rConfigItem
.IsAuthentication() &&
164 !rConfigItem
.IsSMTPAfterPOP() &&
165 rConfigItem
.GetMailUserName().getLength())
167 String sPasswd
= rConfigItem
.GetMailPassword();
168 if(rOutMailServerPassword
.Len())
169 sPasswd
= rOutMailServerPassword
;
171 new SwAuthenticator(rConfigItem
.GetMailUserName(),
173 pDialogParentWindow
);
176 xAuthenticator
= new SwAuthenticator();
177 //just to check if the server exists
178 xSmtpServer
->getSupportedConnectionTypes();
181 uno::Reference
< uno::XCurrentContext
> xConnectionContext
=
182 new SwConnectionContext(
183 rConfigItem
.GetMailServer(),
184 rConfigItem
.GetMailPort(),
185 ::rtl::OUString::createFromAscii( rConfigItem
.IsSecureConnection() ? "Ssl" : "Insecure"));
186 xSmtpServer
->connect(xConnectionContext
, xAuthenticator
);
187 rxInMailService
= uno::Reference
< mail::XMailService
>( xSmtpServer
, uno::UNO_QUERY
);
189 catch(uno::Exception
& )
191 DBG_ERROR("exception caught");
199 /*-- 06.04.2004 10:31:27---------------------------------------------------
201 -----------------------------------------------------------------------*/
202 SwBoldFixedInfo::SwBoldFixedInfo(Window
* pParent
, const ResId
& rResId
) :
203 FixedInfo(pParent
, rResId
)
205 Font aFont
= GetFont();
206 aFont
.SetWeight( WEIGHT_BOLD
);
209 /*-- 06.04.2004 10:31:27---------------------------------------------------
211 -----------------------------------------------------------------------*/
212 SwBoldFixedInfo::~SwBoldFixedInfo()
215 struct SwAddressPreview_Impl
217 ::std::vector
< ::rtl::OUString
> aAdresses
;
220 sal_uInt16 nSelectedAddress
;
221 bool bEnableScrollBar
;
223 SwAddressPreview_Impl() :
227 bEnableScrollBar(false)
231 /*-- 27.04.2004 14:01:22---------------------------------------------------
233 -----------------------------------------------------------------------*/
234 SwAddressPreview::SwAddressPreview(Window
* pParent
, const ResId rResId
) :
235 Window( pParent
, rResId
),
236 aVScrollBar(this, WB_VSCROLL
),
237 pImpl(new SwAddressPreview_Impl())
239 aVScrollBar
.SetScrollHdl(LINK(this, SwAddressPreview
, ScrollHdl
));
240 Size
aSize(GetOutputSizePixel());
241 Size
aScrollSize(aVScrollBar
.GetSizePixel());
242 aScrollSize
.Height() = aSize
.Height();
243 aVScrollBar
.SetSizePixel(aScrollSize
);
244 Point
aSrollPos(aSize
.Width() - aScrollSize
.Width(), 0);
245 aVScrollBar
.SetPosPixel(aSrollPos
);
248 /*-- 27.04.2004 14:01:22---------------------------------------------------
250 -----------------------------------------------------------------------*/
251 SwAddressPreview::~SwAddressPreview()
254 /*-- 25.06.2004 11:50:55---------------------------------------------------
256 -----------------------------------------------------------------------*/
257 IMPL_LINK(SwAddressPreview
, ScrollHdl
, ScrollBar
*, EMPTYARG
)
262 /*-- 27.04.2004 14:01:22---------------------------------------------------
264 -----------------------------------------------------------------------*/
265 void SwAddressPreview::AddAddress(const ::rtl::OUString
& rAddress
)
267 pImpl
->aAdresses
.push_back(rAddress
);
270 /*-- 27.04.2004 14:01:23---------------------------------------------------
272 -----------------------------------------------------------------------*/
273 void SwAddressPreview::SetAddress(const ::rtl::OUString
& rAddress
)
275 pImpl
->aAdresses
.clear();
276 pImpl
->aAdresses
.push_back(rAddress
);
277 aVScrollBar
.Show(FALSE
);
280 /*-- 27.04.2004 14:01:23---------------------------------------------------
282 -----------------------------------------------------------------------*/
283 sal_uInt16
SwAddressPreview::GetSelectedAddress()const
285 DBG_ASSERT(pImpl
->nSelectedAddress
< pImpl
->aAdresses
.size(), "selection invalid");
286 return pImpl
->nSelectedAddress
;
288 /*-- 25.06.2004 10:32:48---------------------------------------------------
290 -----------------------------------------------------------------------*/
291 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect
)
293 DBG_ASSERT(pImpl
->nSelectedAddress
< pImpl
->aAdresses
.size(), "selection invalid");
294 pImpl
->nSelectedAddress
= nSelect
;
295 // now make it visible..
296 sal_uInt16 nSelectRow
= nSelect
/ pImpl
->nColumns
;
297 sal_uInt16 nStartRow
= (sal_uInt16
)aVScrollBar
.GetThumbPos();
298 if( (nSelectRow
< nStartRow
) || (nSelectRow
>= (nStartRow
+ pImpl
->nRows
) ))
299 aVScrollBar
.SetThumbPos( nSelectRow
);
301 /*-- 25.06.2004 11:00:40---------------------------------------------------
303 -----------------------------------------------------------------------*/
304 void SwAddressPreview::Clear()
306 pImpl
->aAdresses
.clear();
307 pImpl
->nSelectedAddress
= 0;
310 /*-- 28.04.2004 12:05:50---------------------------------------------------
312 -----------------------------------------------------------------------*/
313 void SwAddressPreview::ReplaceSelectedAddress(const ::rtl::OUString
& rNew
)
315 pImpl
->aAdresses
[pImpl
->nSelectedAddress
] = rNew
;
318 /*-- 25.06.2004 11:30:41---------------------------------------------------
320 -----------------------------------------------------------------------*/
321 void SwAddressPreview::RemoveSelectedAddress()
323 pImpl
->aAdresses
.erase(pImpl
->aAdresses
.begin() + pImpl
->nSelectedAddress
);
324 if(pImpl
->nSelectedAddress
)
325 --pImpl
->nSelectedAddress
;
329 /*-- 27.04.2004 14:01:23---------------------------------------------------
331 -----------------------------------------------------------------------*/
332 void SwAddressPreview::SetLayout(sal_uInt16 nRows
, sal_uInt16 nColumns
)
334 pImpl
->nRows
= nRows
;
335 pImpl
->nColumns
= nColumns
;
338 /*-- 25.06.2004 13:54:03---------------------------------------------------
340 -----------------------------------------------------------------------*/
341 void SwAddressPreview::EnableScrollBar(bool bEnable
)
343 pImpl
->bEnableScrollBar
= bEnable
;
345 /*-- 25.06.2004 11:55:52---------------------------------------------------
347 -----------------------------------------------------------------------*/
348 void SwAddressPreview::UpdateScrollBar()
352 aVScrollBar
.SetVisibleSize(pImpl
->nRows
);
353 sal_uInt16 nResultingRows
= (sal_uInt16
)(pImpl
->aAdresses
.size() + pImpl
->nColumns
- 1) / pImpl
->nColumns
;
355 aVScrollBar
.Show(pImpl
->bEnableScrollBar
&& nResultingRows
> pImpl
->nRows
);
356 aVScrollBar
.SetRange(Range(0, nResultingRows
));
357 if(aVScrollBar
.GetThumbPos() > nResultingRows
)
358 aVScrollBar
.SetThumbPos(nResultingRows
);
361 /*-- 27.04.2004 14:01:23---------------------------------------------------
363 -----------------------------------------------------------------------*/
364 void SwAddressPreview::Paint(const Rectangle
&)
366 const StyleSettings
& rSettings
= GetSettings().GetStyleSettings();
367 SetFillColor(rSettings
.GetWindowColor());
368 SetLineColor( Color(COL_TRANSPARENT
) );
369 DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
370 Color
aPaintColor(IsEnabled() ? rSettings
.GetWindowTextColor() : rSettings
.GetDisableColor());
371 SetLineColor(aPaintColor
);
372 Font
aFont(GetFont());
373 aFont
.SetColor(aPaintColor
);
376 Size aSize
= GetOutputSizePixel();
377 sal_uInt16 nStartRow
= 0;
378 if(aVScrollBar
.IsVisible())
380 aSize
.Width() -= aVScrollBar
.GetSizePixel().Width();
381 nStartRow
= (sal_uInt16
)aVScrollBar
.GetThumbPos();
383 Size
aPartSize( aSize
.Width()/pImpl
->nColumns
, aSize
.Height()/pImpl
->nRows
);
384 aPartSize
.Width() -= 2;
385 aPartSize
.Height() -= 2;
387 sal_uInt16 nAddress
= nStartRow
* pImpl
->nColumns
;
388 const sal_uInt16 nNumAddresses
= static_cast< sal_uInt16
>(pImpl
->aAdresses
.size());
389 for(sal_uInt16 nRow
= 0; nRow
< pImpl
->nRows
; ++nRow
)
391 for(sal_uInt16 nCol
= 0; nCol
< pImpl
->nColumns
; ++nCol
)
393 if(nAddress
>= nNumAddresses
)
395 Point
aPos(nCol
* aPartSize
.Width(), (nRow
) * aPartSize
.Height());
397 bool bIsSelected
= nAddress
== pImpl
->nSelectedAddress
;
398 if((pImpl
->nColumns
* pImpl
->nRows
) == 1)
400 ::rtl::OUString
adr(pImpl
->aAdresses
[nAddress
]);
401 DrawText_Impl(adr
,aPos
,aPartSize
,bIsSelected
);
408 /*-- 07.06.2004 15:44:15---------------------------------------------------
410 -----------------------------------------------------------------------*/
411 void SwAddressPreview::MouseButtonDown( const MouseEvent
& rMEvt
)
413 Window::MouseButtonDown(rMEvt
);
414 if(rMEvt
.IsLeft() && ( pImpl
->nRows
|| pImpl
->nColumns
))
416 //determine the selected address
417 const Point
& rMousePos
= rMEvt
.GetPosPixel();
418 Size
aSize(GetOutputSizePixel());
419 Size
aPartSize( aSize
.Width()/pImpl
->nColumns
, aSize
.Height()/pImpl
->nRows
);
420 sal_uInt32 nRow
= rMousePos
.Y() / aPartSize
.Height() ;
421 if(aVScrollBar
.IsVisible())
423 nRow
+= (sal_uInt16
)aVScrollBar
.GetThumbPos();
425 sal_uInt32 nCol
= rMousePos
.X() / aPartSize
.Width();
426 sal_uInt32 nSelect
= nRow
* pImpl
->nColumns
+ nCol
;
428 if( nSelect
< pImpl
->aAdresses
.size() &&
429 pImpl
->nSelectedAddress
!= (sal_uInt16
)nSelect
)
431 pImpl
->nSelectedAddress
= (sal_uInt16
)nSelect
;
432 m_aSelectHdl
.Call(this);
437 /*-- 01.07.2004 12:33:59---------------------------------------------------
439 -----------------------------------------------------------------------*/
440 void SwAddressPreview::KeyInput( const KeyEvent
& rKEvt
)
442 USHORT nKey
= rKEvt
.GetKeyCode().GetCode();
443 if(pImpl
->nRows
|| pImpl
->nColumns
)
445 sal_uInt32 nSelectedRow
= (pImpl
->nSelectedAddress
+ 1)/ pImpl
->nColumns
;
446 sal_uInt32 nSelectedColumn
= pImpl
->nSelectedAddress
% nSelectedRow
;
454 if(pImpl
->aAdresses
.size() > sal_uInt32(pImpl
->nSelectedAddress
+ pImpl
->nColumns
))
462 if(nSelectedColumn
< sal_uInt32(pImpl
->nColumns
- 1) &&
463 pImpl
->aAdresses
.size() - 1 > pImpl
->nSelectedAddress
)
467 sal_uInt32 nSelect
= nSelectedRow
* pImpl
->nColumns
+ nSelectedColumn
;
468 if( nSelect
< pImpl
->aAdresses
.size() &&
469 pImpl
->nSelectedAddress
!= (sal_uInt16
)nSelect
)
471 pImpl
->nSelectedAddress
= (sal_uInt16
)nSelect
;
472 m_aSelectHdl
.Call(this);
477 Window::KeyInput(rKEvt
);
479 /*-- 05.07.2004 12:02:28---------------------------------------------------
481 -----------------------------------------------------------------------*/
482 void SwAddressPreview::StateChanged( StateChangedType nStateChange
)
484 if(nStateChange
== STATE_CHANGE_ENABLE
)
486 Window::StateChanged(nStateChange
);
488 /*-- 27.04.2004 14:01:23---------------------------------------------------
490 -----------------------------------------------------------------------*/
491 void SwAddressPreview::DrawText_Impl(
492 const ::rtl::OUString
& rAddress
, const Point
& rTopLeft
, const Size
& rSize
, bool bIsSelected
)
494 SetClipRegion( Region( Rectangle(rTopLeft
, rSize
)) );
497 //selection rectangle
498 SetFillColor(Color(COL_TRANSPARENT
));
499 DrawRect(Rectangle(rTopLeft
, rSize
));
501 sal_Int32 nHeight
= GetTextHeight();
502 String
sAddress(rAddress
);
503 sal_uInt16 nTokens
= sAddress
.GetTokenCount('\n');
504 Point aStart
= rTopLeft
;
505 //put it away from the border
507 for(sal_uInt16 nToken
= 0; nToken
< nTokens
; nToken
++)
509 DrawText( aStart
, sAddress
.GetToken(nToken
, '\n') );
510 aStart
.Y() += nHeight
;
513 /*-- 29.04.2004 11:24:47---------------------------------------------------
515 -----------------------------------------------------------------------*/
516 String
SwAddressPreview::FillData(
517 const ::rtl::OUString
& rAddress
,
518 SwMailMergeConfigItem
& rConfigItem
,
519 const Sequence
< ::rtl::OUString
>* pAssignments
)
521 //find the column names in the address string (with name assignment!) and
522 //exchange the placeholder (like <Firstname>) with the database content
523 //unassigned columns are expanded to <not assigned>
524 Reference
< XColumnsSupplier
> xColsSupp( rConfigItem
.GetResultSet(), UNO_QUERY
);
525 Reference
<XNameAccess
> xColAccess
= xColsSupp
.is() ? xColsSupp
->getColumns() : 0;
526 Sequence
< ::rtl::OUString
> aAssignment
= pAssignments
?
528 rConfigItem
.GetColumnAssignment(
529 rConfigItem
.GetCurrentDBData() );
530 const ::rtl::OUString
* pAssignment
= aAssignment
.getConstArray();
531 const ResStringArray
& rDefHeaders
= rConfigItem
.GetDefaultAddressHeaders();
532 String
sAddress(rAddress
);
533 String
sNotAssigned(SW_RES(STR_NOTASSIGNED
));
534 sNotAssigned
.Insert('<', 0);
537 sal_Bool bIncludeCountry
= rConfigItem
.IsIncludeCountry();
538 const ::rtl::OUString rExcludeCountry
= rConfigItem
.GetExcludeCountry();
539 bool bSpecialReplacementForCountry
= (!bIncludeCountry
|| rExcludeCountry
.getLength());
540 String sCountryColumn
;
541 if( bSpecialReplacementForCountry
)
543 sCountryColumn
= rDefHeaders
.GetString(MM_PART_COUNTRY
);
544 Sequence
< ::rtl::OUString
> aSpecialAssignment
=
545 rConfigItem
.GetColumnAssignment( rConfigItem
.GetCurrentDBData() );
546 if(aSpecialAssignment
.getLength() > MM_PART_COUNTRY
&& aSpecialAssignment
[MM_PART_COUNTRY
].getLength())
547 sCountryColumn
= aSpecialAssignment
[MM_PART_COUNTRY
];
550 SwAddressIterator
aIter(sAddress
);
552 while(aIter
.HasMore())
554 SwMergeAddressItem aItem
= aIter
.Next();
557 //get the default column name
559 //find the appropriate assignment
560 String sConvertedColumn
= aItem
.sText
;
561 for(USHORT nColumn
= 0;
562 nColumn
< rDefHeaders
.Count() && nColumn
< aAssignment
.getLength();
565 if(rDefHeaders
.GetString(nColumn
) == aItem
.sText
&&
566 pAssignment
[nColumn
].getLength())
568 sConvertedColumn
= pAssignment
[nColumn
];
572 if(sConvertedColumn
.Len() &&
574 xColAccess
->hasByName(sConvertedColumn
))
576 //get the content and exchange it in the address string
577 Any aCol
= xColAccess
->getByName(sConvertedColumn
);
578 Reference
< XColumn
> xColumn
;
584 ::rtl::OUString sReplace
= xColumn
->getString();
586 if( bSpecialReplacementForCountry
&& sCountryColumn
== sConvertedColumn
)
588 if( rExcludeCountry
.getLength() && sReplace
!= rExcludeCountry
)
589 aItem
.sText
= sReplace
;
595 aItem
.sText
= sReplace
;
598 catch( sdbc::SQLException
& )
600 DBG_ERROR("SQLException caught");
606 aItem
.sText
= sNotAssigned
;
610 sAddress
+= aItem
.sText
;
615 /*-- 11.05.2004 15:42:08---------------------------------------------------
617 -----------------------------------------------------------------------*/
618 SwMergeAddressItem
SwAddressIterator::Next()
620 //currently the string may either start with a '<' then it's a column
621 //otherwise it's simple text maybe containing a return
622 SwMergeAddressItem aRet
;
625 if(sAddress
.GetChar(0) == '<')
627 aRet
.bIsColumn
= true;
628 xub_StrLen nClose
= sAddress
.Search('>');
629 DBG_ASSERT(nClose
!= STRING_NOTFOUND
, "closing '>' not found");
630 if( nClose
!= STRING_NOTFOUND
)
632 aRet
.sText
= sAddress
.Copy(1, nClose
- 1);
633 sAddress
.Erase(0, nClose
+ 1);
637 aRet
.sText
= sAddress
.Copy(1, 1);
638 sAddress
.Erase(0, 1);
643 xub_StrLen nOpen
= sAddress
.Search('<');
644 xub_StrLen nReturn
= sAddress
.Search('\n');
647 aRet
.bIsReturn
= true;
649 sAddress
.Erase(0, 1);
651 else if(STRING_NOTFOUND
== nOpen
&& STRING_NOTFOUND
== nReturn
)
653 nOpen
= sAddress
.Len();
654 aRet
.sText
= sAddress
;
659 xub_StrLen nTarget
= ::std::min(nOpen
, nReturn
);
660 aRet
.sText
= sAddress
.Copy(0, nTarget
);
661 sAddress
.Erase(0, nTarget
);
668 /*-- 21.05.2004 10:36:20---------------------------------------------------
670 -----------------------------------------------------------------------*/
671 SwAuthenticator::~SwAuthenticator()
674 /*-- 21.05.2004 10:36:20---------------------------------------------------
676 -----------------------------------------------------------------------*/
677 OUString
SwAuthenticator::getUserName( ) throw (RuntimeException
)
681 /*-- 21.05.2004 10:36:20---------------------------------------------------
683 -----------------------------------------------------------------------*/
684 OUString
SwAuthenticator::getPassword( ) throw (RuntimeException
)
686 if(m_aUserName
.getLength() && !m_aPassword
.getLength() && m_pParentWindow
)
688 SfxPasswordDialog
* pPasswdDlg
=
689 new SfxPasswordDialog( m_pParentWindow
);
690 pPasswdDlg
->SetMinLen( 0 );
691 if(RET_OK
== pPasswdDlg
->Execute())
692 m_aPassword
= pPasswdDlg
->GetPassword();
696 /*-- 25.08.2004 12:53:03---------------------------------------------------
698 -----------------------------------------------------------------------*/
699 SwConnectionContext::SwConnectionContext(
700 const ::rtl::OUString
& rMailServer
, sal_Int16 nPort
,
701 const ::rtl::OUString
& rConnectionType
) :
702 m_sMailServer(rMailServer
),
704 m_sConnectionType(rConnectionType
)
707 /*-- 25.08.2004 12:53:03---------------------------------------------------
709 -----------------------------------------------------------------------*/
710 SwConnectionContext::~SwConnectionContext()
713 /*-- 25.08.2004 12:53:03---------------------------------------------------
715 -----------------------------------------------------------------------*/
716 uno::Any
SwConnectionContext::getValueByName( const ::rtl::OUString
& rName
)
717 throw (uno::RuntimeException
)
720 if( !rName
.compareToAscii( "ServerName" ))
721 aRet
<<= m_sMailServer
;
722 else if( !rName
.compareToAscii( "Port" ))
723 aRet
<<= (sal_Int32
) m_nPort
;
724 else if( !rName
.compareToAscii( "ConnectionType" ))
725 aRet
<<= m_sConnectionType
;
728 /*-- 21.05.2004 10:45:33---------------------------------------------------
730 -----------------------------------------------------------------------*/
731 SwConnectionListener::~SwConnectionListener()
734 /*-- 21.05.2004 10:45:33---------------------------------------------------
736 -----------------------------------------------------------------------*/
737 void SwConnectionListener::connected(const lang::EventObject
& /*aEvent*/)
738 throw (uno::RuntimeException
)
740 //OSL_ENSURE(false, "Connection opened");
742 /*-- 21.05.2004 10:45:33---------------------------------------------------
744 -----------------------------------------------------------------------*/
745 void SwConnectionListener::disconnected(const lang::EventObject
& /*aEvent*/)
746 throw (uno::RuntimeException
)
748 //OSL_ENSURE(false, "Connection closed");
750 /*-- 21.05.2004 10:45:33---------------------------------------------------
752 -----------------------------------------------------------------------*/
753 void SwConnectionListener::disposing(const lang::EventObject
& /*aEvent*/)
754 throw(uno::RuntimeException
)
757 /*-- 21.05.2004 10:17:22---------------------------------------------------
759 -----------------------------------------------------------------------*/
760 uno::Reference
< uno::XComponentContext
> getCurrentCmpCtx(
761 uno::Reference
<lang::XMultiServiceFactory
> rSrvMgr
)
763 uno::Reference
< beans::XPropertySet
> xPropSet
=
764 uno::Reference
< beans::XPropertySet
>(rSrvMgr
, uno::UNO_QUERY
);
765 Any aAny
= xPropSet
->getPropertyValue( ::rtl::OUString::createFromAscii("DefaultContext"));
766 uno::Reference
< uno::XComponentContext
> rCmpCtx
;
770 /*-- 13.07.2004 09:07:01---------------------------------------------------
772 -----------------------------------------------------------------------*/
773 SwMailTransferable::SwMailTransferable(const rtl::OUString
& rBody
, const rtl::OUString
& rMimeType
) :
774 cppu::WeakComponentImplHelper2
< datatransfer::XTransferable
, beans::XPropertySet
>(m_aMutex
),
775 m_aMimeType( rMimeType
),
780 /*-- 13.07.2004 09:07:01---------------------------------------------------
782 -----------------------------------------------------------------------*/
783 SwMailTransferable::SwMailTransferable(const rtl::OUString
& rURL
,
784 const rtl::OUString
& rName
, const rtl::OUString
& rMimeType
) :
785 cppu::WeakComponentImplHelper2
< datatransfer::XTransferable
, beans::XPropertySet
>(m_aMutex
),
786 m_aMimeType( rMimeType
),
792 /*-- 13.07.2004 09:07:08---------------------------------------------------
794 -----------------------------------------------------------------------*/
795 SwMailTransferable::~SwMailTransferable()
798 /*-- 13.07.2004 09:07:08---------------------------------------------------
800 -----------------------------------------------------------------------*/
801 uno::Any
SwMailTransferable::getTransferData( const datatransfer::DataFlavor
& /*aFlavor*/ )
802 throw (datatransfer::UnsupportedFlavorException
,
803 io::IOException
, uno::RuntimeException
)
807 aRet
<<= ::rtl::OUString(m_sBody
);
810 Sequence
<sal_Int8
> aData
;
811 SfxMedium
aMedium( m_aURL
, STREAM_STD_READ
, FALSE
);
812 SvStream
* pStream
= aMedium
.GetInStream();
813 if ( aMedium
.GetErrorCode() == ERRCODE_NONE
&& pStream
)
815 pStream
->Seek(STREAM_SEEK_TO_END
);
816 aData
.realloc(pStream
->Tell());
818 sal_Int8
* pData
= aData
.getArray();
819 pStream
->Read( pData
, aData
.getLength() );
825 /*-- 13.07.2004 09:07:08---------------------------------------------------
827 -----------------------------------------------------------------------*/
828 uno::Sequence
< datatransfer::DataFlavor
> SwMailTransferable::getTransferDataFlavors( )
829 throw (uno::RuntimeException
)
831 uno::Sequence
< datatransfer::DataFlavor
> aRet(1);
832 aRet
[0].MimeType
= m_aMimeType
;
835 aRet
[0].DataType
= getCppuType((::rtl::OUString
*)0);
839 aRet
[0].HumanPresentableName
= m_aName
;
840 aRet
[0].DataType
= getCppuType((uno::Sequence
<sal_Int8
>*)0);
844 /*-- 13.07.2004 09:07:08---------------------------------------------------
846 -----------------------------------------------------------------------*/
847 sal_Bool
SwMailTransferable::isDataFlavorSupported(
848 const datatransfer::DataFlavor
& aFlavor
)
849 throw (uno::RuntimeException
)
851 return (aFlavor
.MimeType
== ::rtl::OUString(m_aMimeType
));
853 /*-- 28.04.2004 09:52:05---------------------------------------------------
855 -----------------------------------------------------------------------*/
856 uno::Reference
< beans::XPropertySetInfo
> SwMailTransferable::getPropertySetInfo( ) throw(uno::RuntimeException
)
858 return uno::Reference
< beans::XPropertySetInfo
>();
860 /*-- 28.04.2004 09:52:05---------------------------------------------------
862 -----------------------------------------------------------------------*/
863 void SwMailTransferable::setPropertyValue( const ::rtl::OUString
& , const uno::Any
& )
864 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
,
865 lang::WrappedTargetException
, uno::RuntimeException
)
868 /*-- 28.04.2004 09:52:05---------------------------------------------------
870 -----------------------------------------------------------------------*/
871 uno::Any
SwMailTransferable::getPropertyValue( const ::rtl::OUString
& rPropertyName
)
872 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
875 if( rPropertyName
.equalsAscii( "URL" ) )
879 /*-- 28.04.2004 09:52:05---------------------------------------------------
881 -----------------------------------------------------------------------*/
882 void SwMailTransferable::addPropertyChangeListener(
883 const ::rtl::OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& )
884 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
887 /*-- 28.04.2004 09:52:05---------------------------------------------------
889 -----------------------------------------------------------------------*/
890 void SwMailTransferable::removePropertyChangeListener(
891 const ::rtl::OUString
&,
892 const uno::Reference
< beans::XPropertyChangeListener
>& )
893 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
896 /*-- 28.04.2004 09:52:05---------------------------------------------------
898 -----------------------------------------------------------------------*/
899 void SwMailTransferable::addVetoableChangeListener(
900 const ::rtl::OUString
&,
901 const uno::Reference
< beans::XVetoableChangeListener
>& )
902 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
905 /*-- 28.04.2004 09:52:05---------------------------------------------------
907 -----------------------------------------------------------------------*/
908 void SwMailTransferable::removeVetoableChangeListener(
909 const ::rtl::OUString
& ,
910 const uno::Reference
< beans::XVetoableChangeListener
>& )
911 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
915 /*-- 22.06.2004 16:46:05---------------------------------------------------
917 -----------------------------------------------------------------------*/
918 SwMailMessage::SwMailMessage() :
919 cppu::WeakComponentImplHelper1
< mail::XMailMessage
>(m_aMutex
)
922 /*-- 22.06.2004 16:46:06---------------------------------------------------
924 -----------------------------------------------------------------------*/
925 SwMailMessage::~SwMailMessage()
928 /*-- 02.07.2007 16:00:07---------------------------------------------------
930 -----------------------------------------------------------------------*/
931 ::rtl::OUString
SwMailMessage::getSenderName() throw (uno::RuntimeException
)
933 return m_sSenderName
;
935 /*-- 22.06.2004 16:46:06---------------------------------------------------
937 -----------------------------------------------------------------------*/
938 ::rtl::OUString
SwMailMessage::getSenderAddress() throw (uno::RuntimeException
)
940 return m_sSenderAddress
;
942 /*-- 22.06.2004 16:46:06---------------------------------------------------
944 -----------------------------------------------------------------------*/
945 ::rtl::OUString
SwMailMessage::getReplyToAddress() throw (uno::RuntimeException
)
947 return m_sReplyToAddress
;
949 /*-- 22.06.2004 16:46:07---------------------------------------------------
951 -----------------------------------------------------------------------*/
952 void SwMailMessage::setReplyToAddress( const ::rtl::OUString
& _replytoaddress
) throw (uno::RuntimeException
)
954 m_sReplyToAddress
= _replytoaddress
;
956 /*-- 22.06.2004 16:46:07---------------------------------------------------
958 -----------------------------------------------------------------------*/
959 ::rtl::OUString
SwMailMessage::getSubject() throw (uno::RuntimeException
)
963 /*-- 22.06.2004 16:46:07---------------------------------------------------
965 -----------------------------------------------------------------------*/
966 void SwMailMessage::setSubject( const ::rtl::OUString
& _subject
) throw (uno::RuntimeException
)
968 m_sSubject
= _subject
;
970 /*-- 13.07.2004 09:57:18---------------------------------------------------
972 -----------------------------------------------------------------------*/
973 uno::Reference
< datatransfer::XTransferable
> SwMailMessage::getBody() throw (uno::RuntimeException
)
977 /*-- 13.07.2004 09:57:18---------------------------------------------------
979 -----------------------------------------------------------------------*/
980 void SwMailMessage::setBody(
981 const uno::Reference
< datatransfer::XTransferable
>& rBody
)
982 throw (uno::RuntimeException
)
986 /*-- 22.06.2004 16:46:08---------------------------------------------------
988 -----------------------------------------------------------------------*/
989 void SwMailMessage::addRecipient( const ::rtl::OUString
& rRecipientAddress
)
990 throw (uno::RuntimeException
)
992 m_aRecipients
.realloc(m_aRecipients
.getLength() + 1);
993 m_aRecipients
[m_aRecipients
.getLength() - 1] = rRecipientAddress
;
995 /*-- 22.06.2004 16:46:09---------------------------------------------------
997 -----------------------------------------------------------------------*/
998 void SwMailMessage::addCcRecipient( const ::rtl::OUString
& rRecipientAddress
)
999 throw (uno::RuntimeException
)
1001 m_aCcRecipients
.realloc(m_aCcRecipients
.getLength() + 1);
1002 m_aCcRecipients
[m_aCcRecipients
.getLength() - 1] = rRecipientAddress
;
1005 /*-- 22.06.2004 16:46:09---------------------------------------------------
1007 -----------------------------------------------------------------------*/
1008 void SwMailMessage::addBccRecipient( const ::rtl::OUString
& rRecipientAddress
) throw (uno::RuntimeException
)
1010 m_aBccRecipients
.realloc(m_aBccRecipients
.getLength() + 1);
1011 m_aBccRecipients
[m_aBccRecipients
.getLength() - 1] = rRecipientAddress
;
1013 /*-- 22.06.2004 16:46:09---------------------------------------------------
1015 -----------------------------------------------------------------------*/
1016 uno::Sequence
< ::rtl::OUString
> SwMailMessage::getRecipients( ) throw (uno::RuntimeException
)
1018 return m_aRecipients
;
1020 /*-- 22.06.2004 16:46:10---------------------------------------------------
1022 -----------------------------------------------------------------------*/
1023 uno::Sequence
< ::rtl::OUString
> SwMailMessage::getCcRecipients( ) throw (uno::RuntimeException
)
1025 return m_aCcRecipients
;
1027 /*-- 22.06.2004 16:46:10---------------------------------------------------
1029 -----------------------------------------------------------------------*/
1030 uno::Sequence
< ::rtl::OUString
> SwMailMessage::getBccRecipients( ) throw (uno::RuntimeException
)
1032 return m_aBccRecipients
;
1034 /*-- 13.07.2004 09:59:48---------------------------------------------------
1036 -----------------------------------------------------------------------*/
1037 void SwMailMessage::addAttachment( const mail::MailAttachment
& rMailAttachment
)
1038 throw (uno::RuntimeException
)
1040 m_aAttachments
.realloc(m_aAttachments
.getLength() + 1);
1041 m_aAttachments
[m_aAttachments
.getLength() - 1] = rMailAttachment
;
1043 /*-- 13.07.2004 09:59:48---------------------------------------------------
1045 -----------------------------------------------------------------------*/
1046 uno::Sequence
< mail::MailAttachment
> SwMailMessage::getAttachments( )
1047 throw (uno::RuntimeException
)
1049 return m_aAttachments
;