1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #include <swtypes.hxx>
31 #include <mailmergehelper.hxx>
32 #include <svtools/stdctrl.hxx>
33 #include <mmconfigitem.hxx>
34 #ifndef _DOCSH_HXX
35 #include <docsh.hxx>
36 #endif
37 #include <sfx2/filedlghelper.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/fcontnr.hxx>
41 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
42 #include <com/sun/star/sdb/XColumn.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
45 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46 #include "com/sun/star/mail/MailServiceProvider.hpp"
47 #include "com/sun/star/mail/XSmtpService.hpp"
48 #include <comphelper/processfactory.hxx>
49 #include <vcl/msgbox.hxx>
50 #ifndef _PASSWD_HXX
51 #include <sfx2/passwd.hxx>
52 #endif
53 
54 #include <dbui.hrc>
55 
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::sdb;
60 using namespace ::com::sun::star::sdbc;
61 using namespace ::com::sun::star::sdbcx;
62 
63 using rtl::OUString;
64 
65 //using ::rtl::OUString;
66 
67 namespace SwMailMergeHelper
68 {
69 
70 /*-- 14.06.2004 12:29:19---------------------------------------------------
71 
72   -----------------------------------------------------------------------*/
73 String  CallSaveAsDialog(String& rFilter)
74 {
75     ErrCode nRet;
76     String sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName()));
77     ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
78                 0,
79                 sFactory );
80 
81     String sRet;
82     nRet = aDialog.Execute();
83     if(ERRCODE_NONE == nRet)
84     {
85         uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
86         sRet = xFP->getFiles().getConstArray()[0];
87         rFilter = aDialog.GetRealFilter();
88     }
89     return sRet;
90 }
91 /*-- 20.08.2004 09:39:18---------------------------------------------------
92     simple address check: check for '@'
93                             for at least one '.' after the '@'
94                             and for at least to characters before and after the dot
95   -----------------------------------------------------------------------*/
96 bool CheckMailAddress( const ::rtl::OUString& rMailAddress )
97 {
98     String sAddress(rMailAddress);
99     if(!(sAddress.GetTokenCount('@') == 2))
100         return false;
101     sAddress = sAddress.GetToken(1, '@');
102     if(sAddress.GetTokenCount('.') < 2)
103         return false;
104     if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
105         return false;
106     return true;
107 }
108 
109 /*-- 28.12.2004 10:16:02---------------------------------------------------
110 
111   -----------------------------------------------------------------------*/
112 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
113         SwMailMergeConfigItem& rConfigItem,
114         uno::Reference< mail::XMailService >&  rxInMailService,
115         const String& rInMailServerPassword,
116         const String& rOutMailServerPassword,
117         Window* pDialogParentWindow )
118 {
119     uno::Reference< mail::XSmtpService > xSmtpServer;
120     uno::Reference< lang::XMultiServiceFactory> rMgr = ::comphelper::getProcessServiceFactory();
121     if (rMgr.is())
122         try
123         {
124             uno::Reference< mail::XMailServiceProvider > xMailServiceProvider =
125                     mail::MailServiceProvider::create(getCurrentCmpCtx(rMgr));
126             xSmtpServer = uno::Reference< mail::XSmtpService > (
127                             xMailServiceProvider->create(
128                             mail::MailServiceType_SMTP
129                             ), uno::UNO_QUERY);
130 
131             uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
132 
133             if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
134             {
135                 uno::Reference< mail::XMailService > xInMailService =
136                         xMailServiceProvider->create(
137                         rConfigItem.IsInServerPOP() ?
138                             mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
139                 //authenticate at the POP or IMAP server first
140                 String sPasswd = rConfigItem.GetInServerPassword();
141 		if(rInMailServerPassword.Len())
142 			sPasswd = rInMailServerPassword;
143 		uno::Reference<mail::XAuthenticator> xAuthenticator =
144                     new SwAuthenticator(
145                         rConfigItem.GetInServerUserName(),
146                         sPasswd,
147                         pDialogParentWindow);
148 
149                 xInMailService->addConnectionListener(xConnectionListener);
150                 //check connection
151                 uno::Reference< uno::XCurrentContext> xConnectionContext =
152                         new SwConnectionContext(
153                             rConfigItem.GetInServerName(),
154                             rConfigItem.GetInServerPort(),
155                             ::rtl::OUString::createFromAscii( "Insecure" ));
156                 xInMailService->connect(xConnectionContext, xAuthenticator);
157                 rxInMailService = xInMailService;
158             }
159             uno::Reference< mail::XAuthenticator> xAuthenticator;
160             if(rConfigItem.IsAuthentication() &&
161                     !rConfigItem.IsSMTPAfterPOP() &&
162                     rConfigItem.GetMailUserName().getLength())
163             {
164                 String sPasswd = rConfigItem.GetMailPassword();
165                 if(rOutMailServerPassword.Len())
166                     sPasswd = rOutMailServerPassword;
167                 xAuthenticator =
168                     new SwAuthenticator(rConfigItem.GetMailUserName(),
169                             sPasswd,
170                             pDialogParentWindow);
171             }
172             else
173                 xAuthenticator =  new SwAuthenticator();
174             //just to check if the server exists
175             xSmtpServer->getSupportedConnectionTypes();
176             //check connection
177 
178             uno::Reference< uno::XCurrentContext> xConnectionContext =
179                     new SwConnectionContext(
180                         rConfigItem.GetMailServer(),
181                         rConfigItem.GetMailPort(),
182                         ::rtl::OUString::createFromAscii( rConfigItem.IsSecureConnection() ? "Ssl" : "Insecure"));
183             xSmtpServer->connect(xConnectionContext, xAuthenticator);
184             rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
185         }
186         catch(uno::Exception& )
187         {
188             DBG_ERROR("exception caught");
189         }
190     return xSmtpServer;
191 }
192 
193 
194 } //namespace
195 
196 /*-- 06.04.2004 10:31:27---------------------------------------------------
197 
198   -----------------------------------------------------------------------*/
199 SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
200     FixedInfo(pParent, rResId)
201 {
202     Font aFont = GetFont();
203     aFont.SetWeight( WEIGHT_BOLD );
204     SetFont( aFont );
205 }
206 /*-- 06.04.2004 10:31:27---------------------------------------------------
207 
208   -----------------------------------------------------------------------*/
209 SwBoldFixedInfo::~SwBoldFixedInfo()
210 {
211 }
212 struct  SwAddressPreview_Impl
213 {
214     ::std::vector< ::rtl::OUString >    aAdresses;
215     sal_uInt16                          nRows;
216     sal_uInt16                          nColumns;
217     sal_uInt16                          nSelectedAddress;
218     bool                                bEnableScrollBar;
219 
220     SwAddressPreview_Impl() :
221         nRows(1),
222         nColumns(1),
223         nSelectedAddress(0),
224         bEnableScrollBar(false)
225     {
226     }
227 };
228 /*-- 27.04.2004 14:01:22---------------------------------------------------
229 
230   -----------------------------------------------------------------------*/
231 SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
232     Window( pParent, rResId ),
233     aVScrollBar(this, WB_VSCROLL),
234     pImpl(new SwAddressPreview_Impl())
235 {
236     aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
237     Size aSize(GetOutputSizePixel());
238     Size aScrollSize(aVScrollBar.GetSizePixel());
239     aScrollSize.Height() = aSize.Height();
240     aVScrollBar.SetSizePixel(aScrollSize);
241     Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
242     aVScrollBar.SetPosPixel(aSrollPos);
243     Show();
244 }
245 /*-- 27.04.2004 14:01:22---------------------------------------------------
246 
247   -----------------------------------------------------------------------*/
248 SwAddressPreview::~SwAddressPreview()
249 {
250 }
251 /*-- 25.06.2004 11:50:55---------------------------------------------------
252 
253   -----------------------------------------------------------------------*/
254 IMPL_LINK(SwAddressPreview, ScrollHdl, ScrollBar*, EMPTYARG)
255 {
256     Invalidate();
257     return 0;
258 }
259 /*-- 27.04.2004 14:01:22---------------------------------------------------
260 
261   -----------------------------------------------------------------------*/
262 void SwAddressPreview::AddAddress(const ::rtl::OUString& rAddress)
263 {
264     pImpl->aAdresses.push_back(rAddress);
265     UpdateScrollBar();
266 }
267 /*-- 27.04.2004 14:01:23---------------------------------------------------
268 
269   -----------------------------------------------------------------------*/
270 void SwAddressPreview::SetAddress(const ::rtl::OUString& rAddress)
271 {
272     pImpl->aAdresses.clear();
273     pImpl->aAdresses.push_back(rAddress);
274     aVScrollBar.Show(sal_False);
275     Invalidate();
276 }
277 /*-- 27.04.2004 14:01:23---------------------------------------------------
278 
279   -----------------------------------------------------------------------*/
280 sal_uInt16   SwAddressPreview::GetSelectedAddress()const
281 {
282     DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
283     return pImpl->nSelectedAddress;
284 }
285 /*-- 25.06.2004 10:32:48---------------------------------------------------
286 
287   -----------------------------------------------------------------------*/
288 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
289 {
290     DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
291     pImpl->nSelectedAddress = nSelect;
292     // now make it visible..
293     sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
294     sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
295     if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
296         aVScrollBar.SetThumbPos( nSelectRow );
297 }
298 /*-- 25.06.2004 11:00:40---------------------------------------------------
299 
300   -----------------------------------------------------------------------*/
301 void SwAddressPreview::Clear()
302 {
303     pImpl->aAdresses.clear();
304     pImpl->nSelectedAddress = 0;
305     UpdateScrollBar();
306 }
307 /*-- 28.04.2004 12:05:50---------------------------------------------------
308 
309   -----------------------------------------------------------------------*/
310 void SwAddressPreview::ReplaceSelectedAddress(const ::rtl::OUString& rNew)
311 {
312     pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
313     Invalidate();
314 }
315 /*-- 25.06.2004 11:30:41---------------------------------------------------
316 
317   -----------------------------------------------------------------------*/
318 void SwAddressPreview::RemoveSelectedAddress()
319 {
320     pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
321     if(pImpl->nSelectedAddress)
322         --pImpl->nSelectedAddress;
323     UpdateScrollBar();
324     Invalidate();
325 }
326 /*-- 27.04.2004 14:01:23---------------------------------------------------
327 
328   -----------------------------------------------------------------------*/
329 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
330 {
331     pImpl->nRows = nRows;
332     pImpl->nColumns = nColumns;
333     UpdateScrollBar();
334 }
335 /*-- 25.06.2004 13:54:03---------------------------------------------------
336 
337   -----------------------------------------------------------------------*/
338 void SwAddressPreview::EnableScrollBar(bool bEnable)
339 {
340     pImpl->bEnableScrollBar = bEnable;
341 }
342 /*-- 25.06.2004 11:55:52---------------------------------------------------
343 
344   -----------------------------------------------------------------------*/
345 void SwAddressPreview::UpdateScrollBar()
346 {
347     if(pImpl->nColumns)
348     {
349         aVScrollBar.SetVisibleSize(pImpl->nRows);
350         sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
351         ++nResultingRows;
352         aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
353         aVScrollBar.SetRange(Range(0, nResultingRows));
354         if(aVScrollBar.GetThumbPos() > nResultingRows)
355             aVScrollBar.SetThumbPos(nResultingRows);
356     }
357 }
358 /*-- 27.04.2004 14:01:23---------------------------------------------------
359 
360   -----------------------------------------------------------------------*/
361 void SwAddressPreview::Paint(const Rectangle&)
362 {
363     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
364     SetFillColor(rSettings.GetWindowColor());
365     SetLineColor( Color(COL_TRANSPARENT) );
366     DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
367     Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
368     SetLineColor(aPaintColor);
369     Font aFont(GetFont());
370     aFont.SetColor(aPaintColor);
371     SetFont(aFont);
372 
373     Size aSize = GetOutputSizePixel();
374     sal_uInt16 nStartRow = 0;
375     if(aVScrollBar.IsVisible())
376     {
377         aSize.Width() -= aVScrollBar.GetSizePixel().Width();
378         nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
379     }
380     Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
381 	aPartSize.Width() -= 2;
382 	aPartSize.Height() -= 2;
383 
384     sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
385     const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
386     for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
387     {
388         for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
389         {
390             if(nAddress >= nNumAddresses)
391                 break;
392             Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
393 			aPos.Move(1,1);
394 			bool bIsSelected = nAddress == pImpl->nSelectedAddress;
395 			if((pImpl->nColumns * pImpl->nRows) == 1)
396 				bIsSelected = false;
397 			::rtl::OUString adr(pImpl->aAdresses[nAddress]);
398             DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
399             ++nAddress;
400         }
401     }
402     SetClipRegion();
403 }
404 
405 /*-- 07.06.2004 15:44:15---------------------------------------------------
406 
407   -----------------------------------------------------------------------*/
408 void  SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
409 {
410     Window::MouseButtonDown(rMEvt);
411     if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
412     {
413         //determine the selected address
414         const Point& rMousePos = rMEvt.GetPosPixel();
415         Size aSize(GetOutputSizePixel());
416         Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
417         sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
418         if(aVScrollBar.IsVisible())
419         {
420             nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
421         }
422         sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
423         sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
424 
425         if( nSelect < pImpl->aAdresses.size() &&
426                 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
427         {
428             pImpl->nSelectedAddress = (sal_uInt16)nSelect;
429             m_aSelectHdl.Call(this);
430         }
431         Invalidate();
432     }
433 }
434 /*-- 01.07.2004 12:33:59---------------------------------------------------
435 
436   -----------------------------------------------------------------------*/
437 void  SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
438 {
439     sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
440     if(pImpl->nRows || pImpl->nColumns)
441     {
442         sal_uInt32 nSelectedRow =    (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
443         sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
444         switch(nKey)
445         {
446             case KEY_UP:
447                 if(nSelectedRow)
448                     --nSelectedRow;
449             break;
450             case KEY_DOWN:
451                 if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
452                     ++nSelectedRow;
453             break;
454             case KEY_LEFT:
455                 if(nSelectedColumn)
456                     --nSelectedColumn;
457             break;
458             case KEY_RIGHT:
459                 if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
460                        pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
461                     ++nSelectedColumn;
462             break;
463         }
464         sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
465         if( nSelect < pImpl->aAdresses.size() &&
466                 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
467         {
468             pImpl->nSelectedAddress = (sal_uInt16)nSelect;
469             m_aSelectHdl.Call(this);
470             Invalidate();
471         }
472     }
473     else
474         Window::KeyInput(rKEvt);
475 }
476 /*-- 05.07.2004 12:02:28---------------------------------------------------
477 
478   -----------------------------------------------------------------------*/
479 void SwAddressPreview::StateChanged( StateChangedType nStateChange )
480 {
481     if(nStateChange == STATE_CHANGE_ENABLE)
482         Invalidate();
483     Window::StateChanged(nStateChange);
484 }
485 /*-- 27.04.2004 14:01:23---------------------------------------------------
486 
487   -----------------------------------------------------------------------*/
488 void SwAddressPreview::DrawText_Impl(
489         const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
490 {
491     SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
492     if(bIsSelected)
493     {
494         //selection rectangle
495         SetFillColor(Color(COL_TRANSPARENT));
496         DrawRect(Rectangle(rTopLeft, rSize));
497     }
498     sal_Int32 nHeight = GetTextHeight();
499     String sAddress(rAddress);
500     sal_uInt16 nTokens = sAddress.GetTokenCount('\n');
501     Point aStart = rTopLeft;
502     //put it away from the border
503     aStart.Move( 2, 2);
504     for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
505     {
506         DrawText( aStart, sAddress.GetToken(nToken, '\n') );
507         aStart.Y() += nHeight;
508     }
509 }
510 /*-- 29.04.2004 11:24:47---------------------------------------------------
511 
512   -----------------------------------------------------------------------*/
513 String SwAddressPreview::FillData(
514         const ::rtl::OUString& rAddress,
515         SwMailMergeConfigItem& rConfigItem,
516         const Sequence< ::rtl::OUString>* pAssignments)
517 {
518     //find the column names in the address string (with name assignment!) and
519     //exchange the placeholder (like <Firstname>) with the database content
520     //unassigned columns are expanded to <not assigned>
521     Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
522     Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
523     Sequence< ::rtl::OUString> aAssignment = pAssignments ?
524                     *pAssignments :
525                     rConfigItem.GetColumnAssignment(
526                                                 rConfigItem.GetCurrentDBData() );
527     const ::rtl::OUString* pAssignment = aAssignment.getConstArray();
528     const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
529     String sAddress(rAddress);
530     String sNotAssigned(SW_RES(STR_NOTASSIGNED));
531     sNotAssigned.Insert('<', 0);
532     sNotAssigned += '>';
533 
534     sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
535     const ::rtl::OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
536     bool bSpecialReplacementForCountry = (!bIncludeCountry || rExcludeCountry.getLength());
537     String sCountryColumn;
538     if( bSpecialReplacementForCountry )
539     {
540         sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
541         Sequence< ::rtl::OUString> aSpecialAssignment =
542                         rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
543         if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
544             sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
545     }
546 
547     SwAddressIterator aIter(sAddress);
548     sAddress.Erase();
549     while(aIter.HasMore())
550     {
551         SwMergeAddressItem aItem = aIter.Next();
552         if(aItem.bIsColumn)
553         {
554             //get the default column name
555 
556             //find the appropriate assignment
557             String sConvertedColumn = aItem.sText;
558             for(sal_uInt16 nColumn = 0;
559                     nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
560                                                                                 ++nColumn)
561             {
562                 if(rDefHeaders.GetString(nColumn) == aItem.sText &&
563                     pAssignment[nColumn].getLength())
564                 {
565                     sConvertedColumn = pAssignment[nColumn];
566                     break;
567                 }
568             }
569             if(sConvertedColumn.Len() &&
570                     xColAccess.is() &&
571                     xColAccess->hasByName(sConvertedColumn))
572             {
573                 //get the content and exchange it in the address string
574                 Any aCol = xColAccess->getByName(sConvertedColumn);
575                 Reference< XColumn > xColumn;
576                 aCol >>= xColumn;
577                 if(xColumn.is())
578                 {
579                     try
580                     {
581                         ::rtl::OUString sReplace = xColumn->getString();
582 
583                         if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
584                         {
585                             if( rExcludeCountry.getLength() && sReplace != rExcludeCountry )
586                                 aItem.sText = sReplace;
587                             else
588                                 aItem.sText.Erase();
589                         }
590                         else
591                         {
592                             aItem.sText = sReplace;
593                         }
594                     }
595                     catch( sdbc::SQLException& )
596                     {
597                         DBG_ERROR("SQLException caught");
598                     }
599                 }
600             }
601             else
602             {
603                 aItem.sText = sNotAssigned;
604             }
605 
606         }
607         sAddress += aItem.sText;
608     }
609     return sAddress;
610 }
611 
612 /*-- 11.05.2004 15:42:08---------------------------------------------------
613 
614   -----------------------------------------------------------------------*/
615 SwMergeAddressItem   SwAddressIterator::Next()
616 {
617     //currently the string may either start with a '<' then it's a column
618     //otherwise it's simple text maybe containing a return
619     SwMergeAddressItem   aRet;
620     if(sAddress.Len())
621     {
622         if(sAddress.GetChar(0) == '<')
623         {
624             aRet.bIsColumn = true;
625             xub_StrLen nClose = sAddress.Search('>');
626             DBG_ASSERT(nClose != STRING_NOTFOUND, "closing '>' not found");
627             if( nClose != STRING_NOTFOUND )
628             {
629                 aRet.sText = sAddress.Copy(1, nClose - 1);
630                 sAddress.Erase(0, nClose + 1);
631             }
632             else
633             {
634                 aRet.sText = sAddress.Copy(1, 1);
635                 sAddress.Erase(0, 1);
636             }
637         }
638         else
639         {
640             xub_StrLen nOpen = sAddress.Search('<');
641             xub_StrLen nReturn = sAddress.Search('\n');
642             if(nReturn == 0)
643             {
644                 aRet.bIsReturn = true;
645                 aRet.sText = '\n';
646                 sAddress.Erase(0, 1);
647             }
648             else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
649             {
650                 nOpen = sAddress.Len();
651                 aRet.sText = sAddress;
652                 sAddress.Erase();
653             }
654             else
655             {
656                 xub_StrLen nTarget = ::std::min(nOpen, nReturn);
657                 aRet.sText = sAddress.Copy(0, nTarget);
658                 sAddress.Erase(0, nTarget);
659             }
660         }
661     }
662     return aRet;
663 
664 }
665 /*-- 21.05.2004 10:36:20---------------------------------------------------
666 
667   -----------------------------------------------------------------------*/
668 SwAuthenticator::~SwAuthenticator()
669 {
670 }
671 /*-- 21.05.2004 10:36:20---------------------------------------------------
672 
673   -----------------------------------------------------------------------*/
674 OUString SwAuthenticator::getUserName( ) throw (RuntimeException)
675 {
676     return m_aUserName;
677 }
678 /*-- 21.05.2004 10:36:20---------------------------------------------------
679 
680   -----------------------------------------------------------------------*/
681 OUString SwAuthenticator::getPassword(  ) throw (RuntimeException)
682 {
683     if(m_aUserName.getLength() && !m_aPassword.getLength() && m_pParentWindow)
684     {
685        SfxPasswordDialog* pPasswdDlg =
686                 new SfxPasswordDialog( m_pParentWindow );
687        pPasswdDlg->SetMinLen( 0 );
688        if(RET_OK == pPasswdDlg->Execute())
689             m_aPassword = pPasswdDlg->GetPassword();
690     }
691     return m_aPassword;
692 }
693 /*-- 25.08.2004 12:53:03---------------------------------------------------
694 
695   -----------------------------------------------------------------------*/
696 SwConnectionContext::SwConnectionContext(
697         const ::rtl::OUString& rMailServer, sal_Int16 nPort,
698         const ::rtl::OUString& rConnectionType) :
699     m_sMailServer(rMailServer),
700     m_nPort(nPort),
701     m_sConnectionType(rConnectionType)
702 {
703 }
704 /*-- 25.08.2004 12:53:03---------------------------------------------------
705 
706   -----------------------------------------------------------------------*/
707 SwConnectionContext::~SwConnectionContext()
708 {
709 }
710 /*-- 25.08.2004 12:53:03---------------------------------------------------
711 
712   -----------------------------------------------------------------------*/
713 uno::Any SwConnectionContext::getValueByName( const ::rtl::OUString& rName )
714                                                 throw (uno::RuntimeException)
715 {
716     uno::Any aRet;
717     if( !rName.compareToAscii( "ServerName" ))
718         aRet <<= m_sMailServer;
719     else if( !rName.compareToAscii( "Port" ))
720         aRet <<= (sal_Int32) m_nPort;
721     else if( !rName.compareToAscii( "ConnectionType" ))
722         aRet <<= m_sConnectionType;
723     return aRet;
724 }
725 /*-- 21.05.2004 10:45:33---------------------------------------------------
726 
727   -----------------------------------------------------------------------*/
728 SwConnectionListener::~SwConnectionListener()
729 {
730 }
731 /*-- 21.05.2004 10:45:33---------------------------------------------------
732 
733   -----------------------------------------------------------------------*/
734 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
735     throw (uno::RuntimeException)
736 {
737     //OSL_ENSURE(false, "Connection opened");
738 }
739 /*-- 21.05.2004 10:45:33---------------------------------------------------
740 
741   -----------------------------------------------------------------------*/
742 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
743     throw (uno::RuntimeException)
744 {
745     //OSL_ENSURE(false, "Connection closed");
746 }
747 /*-- 21.05.2004 10:45:33---------------------------------------------------
748 
749   -----------------------------------------------------------------------*/
750 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
751     throw(uno::RuntimeException)
752 {
753 }
754 /*-- 21.05.2004 10:17:22---------------------------------------------------
755 
756   -----------------------------------------------------------------------*/
757 uno::Reference< uno::XComponentContext> getCurrentCmpCtx(
758                         uno::Reference<lang::XMultiServiceFactory> rSrvMgr)
759 {
760     uno::Reference< beans::XPropertySet > xPropSet =
761                 uno::Reference< beans::XPropertySet>(rSrvMgr, uno::UNO_QUERY);
762     Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii("DefaultContext"));
763     uno::Reference< uno::XComponentContext> rCmpCtx;
764     aAny >>= rCmpCtx;
765     return rCmpCtx;
766 }
767 /*-- 13.07.2004 09:07:01---------------------------------------------------
768 
769   -----------------------------------------------------------------------*/
770 SwMailTransferable::SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType) :
771     cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
772     m_aMimeType( rMimeType ),
773     m_sBody( rBody ),
774     m_bIsBody( true )
775 {
776 }
777 /*-- 13.07.2004 09:07:01---------------------------------------------------
778 
779   -----------------------------------------------------------------------*/
780 SwMailTransferable::SwMailTransferable(const rtl::OUString& rURL,
781                 const rtl::OUString& rName, const rtl::OUString& rMimeType) :
782     cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
783     m_aMimeType( rMimeType ),
784     m_aURL(rURL),
785     m_aName( rName ),
786     m_bIsBody( false )
787 {
788 }
789 /*-- 13.07.2004 09:07:08---------------------------------------------------
790 
791   -----------------------------------------------------------------------*/
792 SwMailTransferable::~SwMailTransferable()
793 {
794 }
795 /*-- 13.07.2004 09:07:08---------------------------------------------------
796 
797   -----------------------------------------------------------------------*/
798 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
799                             throw (datatransfer::UnsupportedFlavorException,
800                             io::IOException, uno::RuntimeException)
801 {
802     uno::Any aRet;
803     if( m_bIsBody )
804         aRet <<= ::rtl::OUString(m_sBody);
805     else
806     {
807         Sequence<sal_Int8> aData;
808         SfxMedium aMedium( m_aURL, STREAM_STD_READ, sal_False );
809         SvStream* pStream = aMedium.GetInStream();
810         if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
811         {
812             pStream->Seek(STREAM_SEEK_TO_END);
813             aData.realloc(pStream->Tell());
814             pStream->Seek(0);
815             sal_Int8 * pData = aData.getArray();
816             pStream->Read( pData, aData.getLength() );
817         }
818         aRet <<= aData;
819     }
820     return aRet;
821 }
822 /*-- 13.07.2004 09:07:08---------------------------------------------------
823 
824   -----------------------------------------------------------------------*/
825 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors(  )
826                             throw (uno::RuntimeException)
827 {
828     uno::Sequence< datatransfer::DataFlavor > aRet(1);
829     aRet[0].MimeType = m_aMimeType;
830     if( m_bIsBody )
831     {
832         aRet[0].DataType = getCppuType((::rtl::OUString*)0);
833     }
834     else
835     {
836         aRet[0].HumanPresentableName = m_aName;
837         aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
838     }
839     return aRet;
840 }
841 /*-- 13.07.2004 09:07:08---------------------------------------------------
842 
843   -----------------------------------------------------------------------*/
844 sal_Bool SwMailTransferable::isDataFlavorSupported(
845             const datatransfer::DataFlavor& aFlavor )
846                             throw (uno::RuntimeException)
847 {
848     return (aFlavor.MimeType == ::rtl::OUString(m_aMimeType));
849 }
850 /*-- 28.04.2004 09:52:05---------------------------------------------------
851 
852   -----------------------------------------------------------------------*/
853 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo(  ) throw(uno::RuntimeException)
854 {
855     return uno::Reference< beans::XPropertySetInfo >();
856 }
857 /*-- 28.04.2004 09:52:05---------------------------------------------------
858 
859   -----------------------------------------------------------------------*/
860 void SwMailTransferable::setPropertyValue( const ::rtl::OUString& , const uno::Any& )
861     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
862           lang::WrappedTargetException, uno::RuntimeException)
863 {
864 }
865 /*-- 28.04.2004 09:52:05---------------------------------------------------
866 
867   -----------------------------------------------------------------------*/
868 uno::Any SwMailTransferable::getPropertyValue( const ::rtl::OUString& rPropertyName )
869     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
870 {
871     uno::Any aRet;
872     if( rPropertyName.equalsAscii( "URL" ) )
873         aRet <<= m_aURL;
874     return aRet;
875 }
876 /*-- 28.04.2004 09:52:05---------------------------------------------------
877 
878   -----------------------------------------------------------------------*/
879 void SwMailTransferable::addPropertyChangeListener(
880     const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >&  )
881     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
882 {
883 }
884 /*-- 28.04.2004 09:52:05---------------------------------------------------
885 
886   -----------------------------------------------------------------------*/
887 void SwMailTransferable::removePropertyChangeListener(
888     const ::rtl::OUString&,
889     const uno::Reference< beans::XPropertyChangeListener >& )
890     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
891 {
892 }
893 /*-- 28.04.2004 09:52:05---------------------------------------------------
894 
895   -----------------------------------------------------------------------*/
896 void SwMailTransferable::addVetoableChangeListener(
897     const ::rtl::OUString&,
898     const uno::Reference< beans::XVetoableChangeListener >& )
899     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
900 {
901 }
902 /*-- 28.04.2004 09:52:05---------------------------------------------------
903 
904   -----------------------------------------------------------------------*/
905 void SwMailTransferable::removeVetoableChangeListener(
906     const ::rtl::OUString& ,
907     const uno::Reference< beans::XVetoableChangeListener >&  )
908         throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
909 {
910 }
911 
912 /*-- 22.06.2004 16:46:05---------------------------------------------------
913 
914   -----------------------------------------------------------------------*/
915 SwMailMessage::SwMailMessage() :
916         cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
917 {
918 }
919 /*-- 22.06.2004 16:46:06---------------------------------------------------
920 
921   -----------------------------------------------------------------------*/
922 SwMailMessage::~SwMailMessage()
923 {
924 }
925 /*-- 02.07.2007 16:00:07---------------------------------------------------
926 
927   -----------------------------------------------------------------------*/
928 ::rtl::OUString SwMailMessage::getSenderName() throw (uno::RuntimeException)
929 {
930     return m_sSenderName;
931 }
932 /*-- 22.06.2004 16:46:06---------------------------------------------------
933 
934   -----------------------------------------------------------------------*/
935 ::rtl::OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException)
936 {
937     return m_sSenderAddress;
938 }
939 /*-- 22.06.2004 16:46:06---------------------------------------------------
940 
941   -----------------------------------------------------------------------*/
942 ::rtl::OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException)
943 {
944     return m_sReplyToAddress;
945 }
946 /*-- 22.06.2004 16:46:07---------------------------------------------------
947 
948   -----------------------------------------------------------------------*/
949 void SwMailMessage::setReplyToAddress( const ::rtl::OUString& _replytoaddress ) throw (uno::RuntimeException)
950 {
951     m_sReplyToAddress = _replytoaddress;
952 }
953 /*-- 22.06.2004 16:46:07---------------------------------------------------
954 
955   -----------------------------------------------------------------------*/
956 ::rtl::OUString SwMailMessage::getSubject() throw (uno::RuntimeException)
957 {
958     return m_sSubject;
959 }
960 /*-- 22.06.2004 16:46:07---------------------------------------------------
961 
962   -----------------------------------------------------------------------*/
963 void SwMailMessage::setSubject( const ::rtl::OUString& _subject ) throw (uno::RuntimeException)
964 {
965     m_sSubject = _subject;
966 }
967 /*-- 13.07.2004 09:57:18---------------------------------------------------
968 
969   -----------------------------------------------------------------------*/
970 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException)
971 {
972     return m_xBody;
973 }
974 /*-- 13.07.2004 09:57:18---------------------------------------------------
975 
976   -----------------------------------------------------------------------*/
977 void SwMailMessage::setBody(
978         const uno::Reference< datatransfer::XTransferable >& rBody )
979                                                 throw (uno::RuntimeException)
980 {
981     m_xBody = rBody;
982 }
983 /*-- 22.06.2004 16:46:08---------------------------------------------------
984 
985   -----------------------------------------------------------------------*/
986 void  SwMailMessage::addRecipient( const ::rtl::OUString& rRecipientAddress )
987         throw (uno::RuntimeException)
988 {
989     m_aRecipients.realloc(m_aRecipients.getLength() + 1);
990     m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
991 }
992 /*-- 22.06.2004 16:46:09---------------------------------------------------
993 
994   -----------------------------------------------------------------------*/
995 void  SwMailMessage::addCcRecipient( const ::rtl::OUString& rRecipientAddress )
996         throw (uno::RuntimeException)
997 {
998     m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
999     m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
1000 
1001 }
1002 /*-- 22.06.2004 16:46:09---------------------------------------------------
1003 
1004   -----------------------------------------------------------------------*/
1005 void  SwMailMessage::addBccRecipient( const ::rtl::OUString& rRecipientAddress ) throw (uno::RuntimeException)
1006 {
1007     m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
1008     m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
1009 }
1010 /*-- 22.06.2004 16:46:09---------------------------------------------------
1011 
1012   -----------------------------------------------------------------------*/
1013 uno::Sequence< ::rtl::OUString > SwMailMessage::getRecipients(  ) throw (uno::RuntimeException)
1014 {
1015     return m_aRecipients;
1016 }
1017 /*-- 22.06.2004 16:46:10---------------------------------------------------
1018 
1019   -----------------------------------------------------------------------*/
1020 uno::Sequence< ::rtl::OUString > SwMailMessage::getCcRecipients(  ) throw (uno::RuntimeException)
1021 {
1022     return m_aCcRecipients;
1023 }
1024 /*-- 22.06.2004 16:46:10---------------------------------------------------
1025 
1026   -----------------------------------------------------------------------*/
1027 uno::Sequence< ::rtl::OUString > SwMailMessage::getBccRecipients(  ) throw (uno::RuntimeException)
1028 {
1029     return m_aBccRecipients;
1030 }
1031 /*-- 13.07.2004 09:59:48---------------------------------------------------
1032 
1033   -----------------------------------------------------------------------*/
1034 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
1035             throw (uno::RuntimeException)
1036 {
1037     m_aAttachments.realloc(m_aAttachments.getLength() + 1);
1038     m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
1039 }
1040 /*-- 13.07.2004 09:59:48---------------------------------------------------
1041 
1042   -----------------------------------------------------------------------*/
1043 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments(  )
1044                                             throw (uno::RuntimeException)
1045 {
1046     return m_aAttachments;
1047 }
1048