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