Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <swtypes.hxx>
21 : #include <mailmergehelper.hxx>
22 : #include <svtools/stdctrl.hxx>
23 : #include <mmconfigitem.hxx>
24 : #include <docsh.hxx>
25 : #include <sfx2/filedlghelper.hxx>
26 : #include <sfx2/docfile.hxx>
27 : #include <sfx2/app.hxx>
28 : #include <sfx2/fcontnr.hxx>
29 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 : #include <com/sun/star/sdb/XColumn.hpp>
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
34 : #include <com/sun/star/mail/MailServiceProvider.hpp>
35 : #include <com/sun/star/mail/XSmtpService.hpp>
36 : #include <comphelper/processfactory.hxx>
37 : #include <comphelper/string.hxx>
38 : #include <vcl/msgbox.hxx>
39 : #include <vcl/settings.hxx>
40 :
41 : #include <sfx2/passwd.hxx>
42 :
43 : #include <dbui.hrc>
44 :
45 : using namespace ::com::sun::star;
46 : using namespace ::com::sun::star::uno;
47 : using namespace ::com::sun::star::container;
48 : using namespace ::com::sun::star::sdb;
49 : using namespace ::com::sun::star::sdbc;
50 : using namespace ::com::sun::star::sdbcx;
51 :
52 : namespace SwMailMergeHelper
53 : {
54 :
55 0 : OUString CallSaveAsDialog(OUString& rFilter)
56 : {
57 : ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
58 : 0,
59 0 : OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
60 :
61 0 : if (aDialog.Execute()!=ERRCODE_NONE)
62 : {
63 0 : return OUString();
64 : }
65 :
66 0 : rFilter = aDialog.GetRealFilter();
67 0 : uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
68 0 : return xFP->getFiles().getConstArray()[0];
69 : }
70 :
71 : /*
72 : simple address check: check for '@'
73 : for at least one '.' after the '@'
74 : and for at least to characters before and after the dot
75 : */
76 0 : bool CheckMailAddress( const OUString& rMailAddress )
77 : {
78 0 : OUString sAddress(rMailAddress);
79 0 : if (!(comphelper::string::getTokenCount(sAddress, '@') == 2))
80 0 : return false;
81 0 : sAddress = sAddress.getToken(1, '@');
82 0 : if (comphelper::string::getTokenCount(sAddress, '.') < 2)
83 0 : return false;
84 0 : if(sAddress.getToken( 0, '.').getLength() < 2 || sAddress.getToken( 1, '.').getLength() < 2)
85 0 : return false;
86 0 : return true;
87 : }
88 :
89 0 : uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
90 : SwMailMergeConfigItem& rConfigItem,
91 : uno::Reference< mail::XMailService >& rxInMailService,
92 : const OUString& rInMailServerPassword,
93 : const OUString& rOutMailServerPassword,
94 : vcl::Window* pDialogParentWindow )
95 : {
96 0 : uno::Reference< mail::XSmtpService > xSmtpServer;
97 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
98 : try
99 : {
100 : uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
101 0 : mail::MailServiceProvider::create( xContext ) );
102 0 : xSmtpServer = uno::Reference< mail::XSmtpService > (
103 0 : xMailServiceProvider->create(
104 : mail::MailServiceType_SMTP
105 0 : ), uno::UNO_QUERY);
106 :
107 0 : uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
108 :
109 0 : if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
110 : {
111 : uno::Reference< mail::XMailService > xInMailService =
112 0 : xMailServiceProvider->create(
113 0 : rConfigItem.IsInServerPOP() ?
114 0 : mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
115 : //authenticate at the POP or IMAP server first
116 0 : OUString sPasswd = rConfigItem.GetInServerPassword();
117 0 : if(!rInMailServerPassword.isEmpty())
118 0 : sPasswd = rInMailServerPassword;
119 : uno::Reference<mail::XAuthenticator> xAuthenticator =
120 : new SwAuthenticator(
121 : rConfigItem.GetInServerUserName(),
122 : sPasswd,
123 0 : pDialogParentWindow);
124 :
125 0 : xInMailService->addConnectionListener(xConnectionListener);
126 : //check connection
127 : uno::Reference< uno::XCurrentContext> xConnectionContext =
128 : new SwConnectionContext(
129 : rConfigItem.GetInServerName(),
130 0 : rConfigItem.GetInServerPort(),
131 0 : OUString("Insecure"));
132 0 : xInMailService->connect(xConnectionContext, xAuthenticator);
133 0 : rxInMailService = xInMailService;
134 : }
135 0 : uno::Reference< mail::XAuthenticator> xAuthenticator;
136 0 : if(rConfigItem.IsAuthentication() &&
137 0 : !rConfigItem.IsSMTPAfterPOP() &&
138 0 : !rConfigItem.GetMailUserName().isEmpty())
139 : {
140 0 : OUString sPasswd = rConfigItem.GetMailPassword();
141 0 : if(!rOutMailServerPassword.isEmpty())
142 0 : sPasswd = rOutMailServerPassword;
143 0 : xAuthenticator =
144 : new SwAuthenticator(rConfigItem.GetMailUserName(),
145 : sPasswd,
146 0 : pDialogParentWindow);
147 : }
148 : else
149 0 : xAuthenticator = new SwAuthenticator();
150 : //just to check if the server exists
151 0 : xSmtpServer->getSupportedConnectionTypes();
152 : //check connection
153 :
154 : uno::Reference< uno::XCurrentContext> xConnectionContext =
155 : new SwConnectionContext(
156 : rConfigItem.GetMailServer(),
157 0 : rConfigItem.GetMailPort(),
158 0 : rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
159 0 : xSmtpServer->connect(xConnectionContext, xAuthenticator);
160 0 : rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
161 : }
162 0 : catch (const uno::Exception&)
163 : {
164 : OSL_FAIL("exception caught");
165 : }
166 0 : return xSmtpServer;
167 : }
168 :
169 : } //namespace
170 :
171 : struct SwAddressPreview_Impl
172 : {
173 : ::std::vector< OUString > aAddresses;
174 : sal_uInt16 nRows;
175 : sal_uInt16 nColumns;
176 : sal_uInt16 nSelectedAddress;
177 : bool bEnableScrollBar;
178 :
179 0 : SwAddressPreview_Impl() :
180 : nRows(1),
181 : nColumns(1),
182 : nSelectedAddress(0),
183 0 : bEnableScrollBar(false)
184 : {
185 0 : }
186 : };
187 :
188 0 : SwAddressPreview::SwAddressPreview(vcl::Window* pParent, WinBits nStyle)
189 : : Window( pParent, nStyle )
190 : , aVScrollBar(this, WB_VSCROLL)
191 0 : , pImpl(new SwAddressPreview_Impl())
192 : {
193 0 : aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
194 0 : positionScrollBar();
195 0 : Show();
196 0 : }
197 :
198 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSwAddressPreview(vcl::Window *pParent, VclBuilder::stringmap &rMap)
199 : {
200 0 : WinBits nWinStyle = WB_DIALOGCONTROL;
201 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
202 0 : if (!sBorder.isEmpty())
203 0 : nWinStyle |= WB_BORDER;
204 0 : return new SwAddressPreview(pParent, nWinStyle);
205 : }
206 :
207 0 : void SwAddressPreview::positionScrollBar()
208 : {
209 0 : Size aSize(GetOutputSizePixel());
210 0 : Size aScrollSize(aVScrollBar.get_preferred_size().Width(), aSize.Height());
211 0 : aVScrollBar.SetSizePixel(aScrollSize);
212 0 : Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
213 0 : aVScrollBar.SetPosPixel(aSrollPos);
214 0 : }
215 :
216 0 : void SwAddressPreview::Resize()
217 : {
218 0 : Window::Resize();
219 0 : positionScrollBar();
220 0 : }
221 :
222 0 : IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl)
223 : {
224 0 : Invalidate();
225 0 : return 0;
226 : }
227 :
228 0 : void SwAddressPreview::AddAddress(const OUString& rAddress)
229 : {
230 0 : pImpl->aAddresses.push_back(rAddress);
231 0 : UpdateScrollBar();
232 0 : }
233 :
234 0 : void SwAddressPreview::SetAddress(const OUString& rAddress)
235 : {
236 0 : pImpl->aAddresses.clear();
237 0 : pImpl->aAddresses.push_back(rAddress);
238 0 : aVScrollBar.Show(false);
239 0 : Invalidate();
240 0 : }
241 :
242 0 : sal_uInt16 SwAddressPreview::GetSelectedAddress()const
243 : {
244 : OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
245 0 : return pImpl->nSelectedAddress;
246 : }
247 :
248 0 : void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
249 : {
250 : OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
251 0 : pImpl->nSelectedAddress = nSelect;
252 : // now make it visible..
253 0 : sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
254 0 : sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
255 0 : if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
256 0 : aVScrollBar.SetThumbPos( nSelectRow );
257 0 : }
258 :
259 0 : void SwAddressPreview::Clear()
260 : {
261 0 : pImpl->aAddresses.clear();
262 0 : pImpl->nSelectedAddress = 0;
263 0 : UpdateScrollBar();
264 0 : }
265 :
266 0 : void SwAddressPreview::ReplaceSelectedAddress(const OUString& rNew)
267 : {
268 0 : pImpl->aAddresses[pImpl->nSelectedAddress] = rNew;
269 0 : Invalidate();
270 0 : }
271 :
272 0 : void SwAddressPreview::RemoveSelectedAddress()
273 : {
274 0 : pImpl->aAddresses.erase(pImpl->aAddresses.begin() + pImpl->nSelectedAddress);
275 0 : if(pImpl->nSelectedAddress)
276 0 : --pImpl->nSelectedAddress;
277 0 : UpdateScrollBar();
278 0 : Invalidate();
279 0 : }
280 :
281 0 : void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
282 : {
283 0 : pImpl->nRows = nRows;
284 0 : pImpl->nColumns = nColumns;
285 0 : UpdateScrollBar();
286 0 : }
287 :
288 0 : void SwAddressPreview::EnableScrollBar(bool bEnable)
289 : {
290 0 : pImpl->bEnableScrollBar = bEnable;
291 0 : }
292 :
293 0 : void SwAddressPreview::UpdateScrollBar()
294 : {
295 0 : if(pImpl->nColumns)
296 : {
297 0 : aVScrollBar.SetVisibleSize(pImpl->nRows);
298 0 : sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
299 0 : ++nResultingRows;
300 0 : aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
301 0 : aVScrollBar.SetRange(Range(0, nResultingRows));
302 0 : if(aVScrollBar.GetThumbPos() > nResultingRows)
303 0 : aVScrollBar.SetThumbPos(nResultingRows);
304 : }
305 0 : }
306 :
307 0 : void SwAddressPreview::Paint(const Rectangle&)
308 : {
309 0 : const StyleSettings& rSettings = GetSettings().GetStyleSettings();
310 0 : SetFillColor(rSettings.GetWindowColor());
311 0 : SetLineColor( Color(COL_TRANSPARENT) );
312 0 : DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
313 0 : Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
314 0 : SetLineColor(aPaintColor);
315 0 : vcl::Font aFont(GetFont());
316 0 : aFont.SetColor(aPaintColor);
317 0 : SetFont(aFont);
318 :
319 0 : Size aSize = GetOutputSizePixel();
320 0 : sal_uInt16 nStartRow = 0;
321 0 : if(aVScrollBar.IsVisible())
322 : {
323 0 : aSize.Width() -= aVScrollBar.GetSizePixel().Width();
324 0 : nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
325 : }
326 0 : Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
327 0 : aPartSize.Width() -= 2;
328 0 : aPartSize.Height() -= 2;
329 :
330 0 : sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
331 0 : const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAddresses.size());
332 0 : for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
333 : {
334 0 : for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
335 : {
336 0 : if(nAddress >= nNumAddresses)
337 0 : break;
338 0 : Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
339 0 : aPos.Move(1,1);
340 0 : bool bIsSelected = nAddress == pImpl->nSelectedAddress;
341 0 : if((pImpl->nColumns * pImpl->nRows) == 1)
342 0 : bIsSelected = false;
343 0 : OUString adr(pImpl->aAddresses[nAddress]);
344 0 : DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
345 0 : ++nAddress;
346 0 : }
347 : }
348 0 : SetClipRegion();
349 0 : }
350 :
351 0 : void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
352 : {
353 0 : Window::MouseButtonDown(rMEvt);
354 0 : if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns)
355 : {
356 : //determine the selected address
357 0 : const Point& rMousePos = rMEvt.GetPosPixel();
358 0 : Size aSize(GetOutputSizePixel());
359 0 : Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
360 0 : sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
361 0 : if(aVScrollBar.IsVisible())
362 : {
363 0 : nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
364 : }
365 0 : sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
366 0 : sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
367 :
368 0 : if( nSelect < pImpl->aAddresses.size() &&
369 0 : pImpl->nSelectedAddress != (sal_uInt16)nSelect)
370 : {
371 0 : pImpl->nSelectedAddress = (sal_uInt16)nSelect;
372 0 : m_aSelectHdl.Call(this);
373 : }
374 0 : Invalidate();
375 : }
376 0 : }
377 :
378 0 : void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
379 : {
380 0 : sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
381 0 : if(pImpl->nRows || pImpl->nColumns)
382 : {
383 0 : sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
384 0 : sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
385 0 : switch(nKey)
386 : {
387 : case KEY_UP:
388 0 : if(nSelectedRow)
389 0 : --nSelectedRow;
390 0 : break;
391 : case KEY_DOWN:
392 0 : if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
393 0 : ++nSelectedRow;
394 0 : break;
395 : case KEY_LEFT:
396 0 : if(nSelectedColumn)
397 0 : --nSelectedColumn;
398 0 : break;
399 : case KEY_RIGHT:
400 0 : if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
401 0 : pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
402 0 : ++nSelectedColumn;
403 0 : break;
404 : }
405 0 : sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
406 0 : if( nSelect < pImpl->aAddresses.size() &&
407 0 : pImpl->nSelectedAddress != (sal_uInt16)nSelect)
408 : {
409 0 : pImpl->nSelectedAddress = (sal_uInt16)nSelect;
410 0 : m_aSelectHdl.Call(this);
411 0 : Invalidate();
412 0 : }
413 : }
414 : else
415 0 : Window::KeyInput(rKEvt);
416 0 : }
417 :
418 0 : void SwAddressPreview::StateChanged( StateChangedType nStateChange )
419 : {
420 0 : if(nStateChange == StateChangedType::ENABLE)
421 0 : Invalidate();
422 0 : Window::StateChanged(nStateChange);
423 0 : }
424 :
425 0 : void SwAddressPreview::DrawText_Impl(
426 : const OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
427 : {
428 0 : SetClipRegion( vcl::Region( Rectangle(rTopLeft, rSize)) );
429 0 : if(bIsSelected)
430 : {
431 : //selection rectangle
432 0 : SetFillColor(Color(COL_TRANSPARENT));
433 0 : DrawRect(Rectangle(rTopLeft, rSize));
434 : }
435 0 : sal_Int32 nHeight = GetTextHeight();
436 0 : OUString sAddress(rAddress);
437 0 : sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n');
438 0 : Point aStart = rTopLeft;
439 : //put it away from the border
440 0 : aStart.Move( 2, 2);
441 0 : for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
442 : {
443 0 : DrawText( aStart, sAddress.getToken(nToken, '\n') );
444 0 : aStart.Y() += nHeight;
445 0 : }
446 0 : }
447 :
448 0 : OUString SwAddressPreview::FillData(
449 : const OUString& rAddress,
450 : SwMailMergeConfigItem& rConfigItem,
451 : const Sequence< OUString>* pAssignments)
452 : {
453 : //find the column names in the address string (with name assignment!) and
454 : //exchange the placeholder (like <Firstname>) with the database content
455 : //unassigned columns are expanded to <not assigned>
456 0 : Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
457 0 : Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
458 : Sequence< OUString> aAssignment = pAssignments ?
459 : *pAssignments :
460 : rConfigItem.GetColumnAssignment(
461 0 : rConfigItem.GetCurrentDBData() );
462 0 : const OUString* pAssignment = aAssignment.getConstArray();
463 0 : const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
464 0 : OUString sAddress(rAddress);
465 0 : OUString sNotAssigned = "<" + OUString(SW_RES(STR_NOTASSIGNED)) + ">";
466 :
467 0 : bool bIncludeCountry = rConfigItem.IsIncludeCountry();
468 0 : const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
469 0 : bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
470 0 : OUString sCountryColumn;
471 0 : if( bSpecialReplacementForCountry )
472 : {
473 0 : sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
474 : Sequence< OUString> aSpecialAssignment =
475 0 : rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
476 0 : if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
477 0 : sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
478 : }
479 :
480 0 : SwAddressIterator aIter(sAddress);
481 0 : sAddress = "";
482 0 : while(aIter.HasMore())
483 : {
484 0 : SwMergeAddressItem aItem = aIter.Next();
485 0 : if(aItem.bIsColumn)
486 : {
487 : //get the default column name
488 :
489 : //find the appropriate assignment
490 0 : OUString sConvertedColumn = aItem.sText;
491 0 : for(sal_uInt16 nColumn = 0;
492 0 : nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
493 : ++nColumn)
494 : {
495 0 : if (rDefHeaders.GetString(nColumn).equals(aItem.sText) &&
496 0 : !pAssignment[nColumn].isEmpty())
497 : {
498 0 : sConvertedColumn = pAssignment[nColumn];
499 0 : break;
500 : }
501 : }
502 0 : if(!sConvertedColumn.isEmpty() &&
503 0 : xColAccess.is() &&
504 0 : xColAccess->hasByName(sConvertedColumn))
505 : {
506 : //get the content and exchange it in the address string
507 0 : Any aCol = xColAccess->getByName(sConvertedColumn);
508 0 : Reference< XColumn > xColumn;
509 0 : aCol >>= xColumn;
510 0 : if(xColumn.is())
511 : {
512 : try
513 : {
514 0 : OUString sReplace = xColumn->getString();
515 :
516 0 : if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
517 : {
518 0 : if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
519 0 : aItem.sText = sReplace;
520 : else
521 0 : aItem.sText = "";
522 : }
523 : else
524 : {
525 0 : aItem.sText = sReplace;
526 0 : }
527 : }
528 0 : catch (const sdbc::SQLException&)
529 : {
530 : OSL_FAIL("SQLException caught");
531 : }
532 0 : }
533 : }
534 : else
535 : {
536 0 : aItem.sText = sNotAssigned;
537 0 : }
538 :
539 : }
540 0 : sAddress += aItem.sText;
541 0 : }
542 0 : return sAddress;
543 : }
544 :
545 232 : SwMergeAddressItem SwAddressIterator::Next()
546 : {
547 : //currently the string may either start with a '<' then it's a column
548 : //otherwise it's simple text maybe containing a return
549 232 : SwMergeAddressItem aRet;
550 232 : if(!sAddress.isEmpty())
551 : {
552 232 : if(sAddress[0] == '<')
553 : {
554 112 : aRet.bIsColumn = true;
555 112 : sal_Int32 nClose = sAddress.indexOf('>');
556 : OSL_ENSURE(nClose != -1, "closing '>' not found");
557 112 : if( nClose != -1 )
558 : {
559 112 : aRet.sText = sAddress.copy(1, nClose - 1);
560 112 : sAddress = sAddress.copy(nClose + 1);
561 : }
562 : else
563 : {
564 0 : aRet.sText = sAddress.copy(1, 1);
565 0 : sAddress = sAddress.copy(1);
566 : }
567 : }
568 : else
569 : {
570 120 : sal_Int32 nOpen = sAddress.indexOf('<');
571 120 : sal_Int32 nReturn = sAddress.indexOf('\n');
572 120 : if(nReturn == 0)
573 : {
574 56 : aRet.bIsReturn = true;
575 56 : aRet.sText = "\n";
576 56 : sAddress = sAddress.copy(1);
577 : }
578 64 : else if(-1 == nOpen && -1 == nReturn)
579 : {
580 24 : aRet.sText = sAddress;
581 24 : sAddress = "";
582 : }
583 : else
584 : {
585 40 : if (nOpen == -1)
586 0 : nOpen = sAddress.getLength();
587 40 : if (nReturn == -1)
588 16 : nReturn = sAddress.getLength();
589 40 : sal_Int32 nTarget = ::std::min(nOpen, nReturn);
590 40 : aRet.sText = sAddress.copy(0, nTarget);
591 40 : sAddress = sAddress.copy(nTarget);
592 : }
593 : }
594 : }
595 232 : return aRet;
596 :
597 : }
598 :
599 0 : SwAuthenticator::~SwAuthenticator()
600 : {
601 0 : }
602 :
603 0 : OUString SwAuthenticator::getUserName( ) throw (RuntimeException, std::exception)
604 : {
605 0 : return m_aUserName;
606 : }
607 :
608 0 : OUString SwAuthenticator::getPassword( ) throw (RuntimeException, std::exception)
609 : {
610 0 : if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
611 : {
612 : SfxPasswordDialog* pPasswdDlg =
613 0 : new SfxPasswordDialog( m_pParentWindow );
614 0 : pPasswdDlg->SetMinLen( 0 );
615 0 : if(RET_OK == pPasswdDlg->Execute())
616 0 : m_aPassword = pPasswdDlg->GetPassword();
617 : }
618 0 : return m_aPassword;
619 : }
620 :
621 0 : SwConnectionContext::SwConnectionContext(
622 : const OUString& rMailServer, sal_Int16 nPort,
623 : const OUString& rConnectionType) :
624 : m_sMailServer(rMailServer),
625 : m_nPort(nPort),
626 0 : m_sConnectionType(rConnectionType)
627 : {
628 0 : }
629 :
630 0 : SwConnectionContext::~SwConnectionContext()
631 : {
632 0 : }
633 :
634 0 : uno::Any SwConnectionContext::getValueByName( const OUString& rName )
635 : throw (uno::RuntimeException, std::exception)
636 : {
637 0 : uno::Any aRet;
638 0 : if( rName.equalsAscii( "ServerName" ))
639 0 : aRet <<= m_sMailServer;
640 0 : else if( rName.equalsAscii( "Port" ))
641 0 : aRet <<= (sal_Int32) m_nPort;
642 0 : else if( rName.equalsAscii( "ConnectionType" ))
643 0 : aRet <<= m_sConnectionType;
644 0 : return aRet;
645 : }
646 :
647 0 : SwConnectionListener::~SwConnectionListener()
648 : {
649 0 : }
650 :
651 0 : void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
652 : throw (uno::RuntimeException, std::exception)
653 : {
654 0 : }
655 :
656 0 : void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
657 : throw (uno::RuntimeException, std::exception)
658 : {
659 0 : }
660 :
661 0 : void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
662 : throw(uno::RuntimeException, std::exception)
663 : {
664 0 : }
665 :
666 0 : SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
667 : cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
668 : m_aMimeType( rMimeType ),
669 : m_sBody( rBody ),
670 0 : m_bIsBody( true )
671 : {
672 0 : }
673 :
674 0 : SwMailTransferable::SwMailTransferable(const OUString& rURL,
675 : const OUString& rName, const OUString& rMimeType) :
676 : cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
677 : m_aMimeType( rMimeType ),
678 : m_aURL(rURL),
679 : m_aName( rName ),
680 0 : m_bIsBody( false )
681 : {
682 0 : }
683 :
684 0 : SwMailTransferable::~SwMailTransferable()
685 : {
686 0 : }
687 :
688 0 : uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
689 : throw (datatransfer::UnsupportedFlavorException,
690 : io::IOException, uno::RuntimeException, std::exception)
691 : {
692 0 : uno::Any aRet;
693 0 : if( m_bIsBody )
694 0 : aRet <<= OUString(m_sBody);
695 : else
696 : {
697 0 : Sequence<sal_Int8> aData;
698 0 : SfxMedium aMedium( m_aURL, STREAM_STD_READ );
699 0 : SvStream* pStream = aMedium.GetInStream();
700 0 : if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
701 : {
702 0 : pStream->Seek(STREAM_SEEK_TO_END);
703 0 : aData.realloc(pStream->Tell());
704 0 : pStream->Seek(0);
705 0 : sal_Int8 * pData = aData.getArray();
706 0 : pStream->Read( pData, aData.getLength() );
707 : }
708 0 : aRet <<= aData;
709 : }
710 0 : return aRet;
711 : }
712 :
713 0 : uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
714 : throw (uno::RuntimeException, std::exception)
715 : {
716 0 : uno::Sequence< datatransfer::DataFlavor > aRet(1);
717 0 : aRet[0].MimeType = m_aMimeType;
718 0 : if( m_bIsBody )
719 : {
720 0 : aRet[0].DataType = cppu::UnoType<OUString>::get();
721 : }
722 : else
723 : {
724 0 : aRet[0].HumanPresentableName = m_aName;
725 0 : aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
726 : }
727 0 : return aRet;
728 : }
729 :
730 0 : sal_Bool SwMailTransferable::isDataFlavorSupported(
731 : const datatransfer::DataFlavor& aFlavor )
732 : throw (uno::RuntimeException, std::exception)
733 : {
734 0 : return (aFlavor.MimeType == m_aMimeType);
735 : }
736 :
737 0 : uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( ) throw(uno::RuntimeException, std::exception)
738 : {
739 0 : return uno::Reference< beans::XPropertySetInfo >();
740 : }
741 :
742 0 : void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
743 : throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
744 : lang::WrappedTargetException, uno::RuntimeException, std::exception)
745 : {
746 0 : }
747 :
748 0 : uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
749 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
750 : {
751 0 : uno::Any aRet;
752 0 : if ( rPropertyName == "URL" )
753 0 : aRet <<= m_aURL;
754 0 : return aRet;
755 : }
756 :
757 0 : void SwMailTransferable::addPropertyChangeListener(
758 : const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
759 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
760 : {
761 0 : }
762 :
763 0 : void SwMailTransferable::removePropertyChangeListener(
764 : const OUString&,
765 : const uno::Reference< beans::XPropertyChangeListener >& )
766 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
767 : {
768 0 : }
769 :
770 0 : void SwMailTransferable::addVetoableChangeListener(
771 : const OUString&,
772 : const uno::Reference< beans::XVetoableChangeListener >& )
773 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
774 : {
775 0 : }
776 :
777 0 : void SwMailTransferable::removeVetoableChangeListener(
778 : const OUString& ,
779 : const uno::Reference< beans::XVetoableChangeListener >& )
780 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
781 : {
782 0 : }
783 :
784 0 : SwMailMessage::SwMailMessage() :
785 0 : cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
786 : {
787 0 : }
788 :
789 0 : SwMailMessage::~SwMailMessage()
790 : {
791 0 : }
792 :
793 0 : OUString SwMailMessage::getSenderName() throw (uno::RuntimeException, std::exception)
794 : {
795 0 : return m_sSenderName;
796 : }
797 :
798 0 : OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException, std::exception)
799 : {
800 0 : return m_sSenderAddress;
801 : }
802 :
803 0 : OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException, std::exception)
804 : {
805 0 : return m_sReplyToAddress;
806 : }
807 :
808 0 : void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress ) throw (uno::RuntimeException, std::exception)
809 : {
810 0 : m_sReplyToAddress = _replytoaddress;
811 0 : }
812 :
813 0 : OUString SwMailMessage::getSubject() throw (uno::RuntimeException, std::exception)
814 : {
815 0 : return m_sSubject;
816 : }
817 :
818 0 : void SwMailMessage::setSubject( const OUString& _subject ) throw (uno::RuntimeException, std::exception)
819 : {
820 0 : m_sSubject = _subject;
821 0 : }
822 :
823 0 : uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException, std::exception)
824 : {
825 0 : return m_xBody;
826 : }
827 :
828 0 : void SwMailMessage::setBody(
829 : const uno::Reference< datatransfer::XTransferable >& rBody )
830 : throw (uno::RuntimeException, std::exception)
831 : {
832 0 : m_xBody = rBody;
833 0 : }
834 :
835 0 : void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
836 : throw (uno::RuntimeException, std::exception)
837 : {
838 0 : m_aRecipients.realloc(m_aRecipients.getLength() + 1);
839 0 : m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
840 0 : }
841 :
842 0 : void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
843 : throw (uno::RuntimeException, std::exception)
844 : {
845 0 : m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
846 0 : m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
847 :
848 0 : }
849 :
850 0 : void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress ) throw (uno::RuntimeException, std::exception)
851 : {
852 0 : m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
853 0 : m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
854 0 : }
855 :
856 0 : uno::Sequence< OUString > SwMailMessage::getRecipients( ) throw (uno::RuntimeException, std::exception)
857 : {
858 0 : return m_aRecipients;
859 : }
860 :
861 0 : uno::Sequence< OUString > SwMailMessage::getCcRecipients( ) throw (uno::RuntimeException, std::exception)
862 : {
863 0 : return m_aCcRecipients;
864 : }
865 :
866 0 : uno::Sequence< OUString > SwMailMessage::getBccRecipients( ) throw (uno::RuntimeException, std::exception)
867 : {
868 0 : return m_aBccRecipients;
869 : }
870 :
871 0 : void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
872 : throw (uno::RuntimeException, std::exception)
873 : {
874 0 : m_aAttachments.realloc(m_aAttachments.getLength() + 1);
875 0 : m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
876 0 : }
877 :
878 0 : uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
879 : throw (uno::RuntimeException, std::exception)
880 : {
881 0 : return m_aAttachments;
882 270 : }
883 :
884 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|