26 #include <com/sun/star/sdbc/SQLException.hpp>
27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28 #include <com/sun/star/sdb/XColumn.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
31 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
32 #include <com/sun/star/mail/MailServiceProvider.hpp>
33 #include <com/sun/star/mail/XSmtpService.hpp>
44 #include <strings.hrc>
59 FileDialogFlags::NONE,
60 SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
68 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.
GetFilePicker();
69 return xFP->getSelectedFiles().getConstArray()[0];
79 const sal_Int32 nPosAt = rMailAddress.indexOf(
'@');
80 if (nPosAt<0 || rMailAddress.lastIndexOf(
'@')!=nPosAt)
82 const sal_Int32 nPosDot = rMailAddress.indexOf(
'.', nPosAt);
83 return !(nPosDot<0 || nPosDot-nPosAt<3 || rMailAddress.getLength()-nPosDot<3);
88 uno::Reference< mail::XMailService >& rxInMailService,
89 const OUString& rInMailServerPassword,
90 const OUString& rOutMailServerPassword,
93 uno::Reference< mail::XSmtpService > xSmtpServer;
94 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
97 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
98 mail::MailServiceProvider::create( xContext ) );
99 xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
105 uno::Reference< mail::XMailService > xInMailService =
106 xMailServiceProvider->create(
108 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
111 if(!rInMailServerPassword.isEmpty())
112 sPasswd = rInMailServerPassword;
113 uno::Reference<mail::XAuthenticator> xAuthenticator =
117 pDialogParentWindow);
119 xInMailService->addConnectionListener(xConnectionListener);
121 uno::Reference< uno::XCurrentContext> xConnectionContext =
126 xInMailService->connect(xConnectionContext, xAuthenticator);
127 rxInMailService = xInMailService;
129 uno::Reference< mail::XAuthenticator> xAuthenticator;
135 if(!rOutMailServerPassword.isEmpty())
136 sPasswd = rOutMailServerPassword;
140 pDialogParentWindow);
145 xSmtpServer->getSupportedConnectionTypes();
148 uno::Reference< uno::XCurrentContext> xConnectionContext =
153 xSmtpServer->connect(xConnectionContext, xAuthenticator);
154 rxInMailService = xSmtpServer;
156 catch (
const uno::Exception&)
177 bEnableScrollBar(false)
183 const OUString& rAddress,
190 Reference< XColumnsSupplier > xColsSupp( rConfigItem.
GetResultSet(), UNO_QUERY);
196 const OUString* pAssignment = aAssignment.getConstArray();
198 OUString sNotAssigned =
"<" +
SwResId(STR_NOTASSIGNED) +
">";
202 bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
203 OUString sCountryColumn;
204 if( bSpecialReplacementForCountry )
206 sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
209 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
210 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
214 OUStringBuffer sAddress;
223 OUString sConvertedColumn = aItem.
sText;
224 auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
225 for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
227 if (rDefHeaders[nColumn].
first == aItem.
sText &&
228 !pAssignment[nColumn].isEmpty())
230 sConvertedColumn = pAssignment[nColumn];
234 if(!sConvertedColumn.isEmpty() &&
236 xColAccess->hasByName(sConvertedColumn))
239 Any aCol = xColAccess->getByName(sConvertedColumn);
246 OUString sReplace = xColumn->getString();
248 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
250 if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
251 aItem.
sText = sReplace;
257 aItem.
sText = sReplace;
260 catch (
const sdbc::SQLException&)
268 aItem.
sText = sNotAssigned;
272 sAddress.append(aItem.
sText);
274 return sAddress.makeStringAndClear();
279 , m_xVScrollBar(
std::move(xWindow))
295 pImpl->aAddresses.push_back(rAddress);
301 pImpl->aAddresses.clear();
302 pImpl->aAddresses.push_back(rAddress);
309 OSL_ENSURE(
pImpl->nSelectedAddress <
pImpl->aAddresses.size(),
"selection invalid");
310 return pImpl->nSelectedAddress;
315 OSL_ENSURE(
pImpl->nSelectedAddress <
pImpl->aAddresses.size(),
"selection invalid");
316 pImpl->nSelectedAddress = nSelect;
318 sal_uInt16 nSelectRow = nSelect /
pImpl->nColumns;
319 sal_uInt16 nStartRow =
m_xVScrollBar->vadjustment_get_value();
320 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow +
pImpl->nRows) ))
326 pImpl->aAddresses.clear();
327 pImpl->nSelectedAddress = 0;
333 pImpl->aAddresses[
pImpl->nSelectedAddress] = rNew;
339 pImpl->aAddresses.erase(
pImpl->aAddresses.begin() +
pImpl->nSelectedAddress);
340 if(
pImpl->nSelectedAddress)
341 --
pImpl->nSelectedAddress;
348 pImpl->nRows = nRows;
349 pImpl->nColumns = nColumns;
355 pImpl->bEnableScrollBar =
true;
362 sal_uInt16 nResultingRows =
static_cast<sal_uInt16
>(
pImpl->aAddresses.size() +
pImpl->nColumns - 1) /
pImpl->nColumns;
365 if (
nValue > nResultingRows)
367 m_xVScrollBar->set_vpolicy(
pImpl->bEnableScrollBar && nResultingRows >
pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
382 pDefaultDevice->SetPointFont(rRenderContext,
GetDrawingArea()->get_font());
388 sal_uInt16 nStartRow = 0;
397 aPartSize.AdjustHeight( -2 );
399 sal_uInt16 nAddress = nStartRow *
pImpl->nColumns;
400 const sal_uInt16 nNumAddresses =
static_cast<sal_uInt16
>(
pImpl->aAddresses.size());
401 for (sal_uInt16 nRow = 0; nRow <
pImpl->nRows ; ++nRow)
403 for (sal_uInt16 nCol = 0; nCol <
pImpl->nColumns; ++nCol)
405 if (nAddress >= nNumAddresses)
407 Point aPos(nCol * aPartSize.Width(),
408 nRow * aPartSize.Height());
410 bool bIsSelected = nAddress ==
pImpl->nSelectedAddress;
413 OUString adr(
pImpl->aAddresses[nAddress]);
414 DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
429 sal_uInt32 nRow = rMousePos.Y() / aPartSize.
Height() ;
434 sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
435 sal_uInt32 nSelect = nRow *
pImpl->nColumns + nCol;
437 if( nSelect < pImpl->aAddresses.size() &&
438 pImpl->nSelectedAddress !=
static_cast<sal_uInt16
>(nSelect))
440 pImpl->nSelectedAddress =
static_cast<sal_uInt16
>(nSelect);
451 bool bHandled =
false;
454 sal_uInt32 nSelectedRow =
pImpl->nSelectedAddress /
pImpl->nColumns;
455 sal_uInt32 nSelectedColumn =
pImpl->nSelectedAddress - (nSelectedRow *
pImpl->nColumns);
475 pImpl->aAddresses.size() - 1 >
pImpl->nSelectedAddress )
480 sal_uInt32 nSelect = nSelectedRow *
pImpl->nColumns + nSelectedColumn;
481 if( nSelect < pImpl->aAddresses.size() &&
482 pImpl->nSelectedAddress !=
static_cast<sal_uInt16
>(nSelect))
484 pImpl->nSelectedAddress =
static_cast<sal_uInt16
>(nSelect);
493 const Point& rTopLeft,
const Size& rSize,
bool bIsSelected)
503 Point aStart = rTopLeft;
509 rRenderContext.
DrawText(aStart, rAddress.getToken(0,
'\n', nPos));
510 aStart.AdjustY(nHeight );
525 sal_Int32 nClose =
sAddress.indexOf(
'>');
526 OSL_ENSURE(nClose != -1,
"closing '>' not found");
540 sal_Int32 nOpen =
sAddress.indexOf(
'<');
541 sal_Int32 nReturn =
sAddress.indexOf(
'\n');
548 else if(-1 == nOpen && -1 == nReturn)
559 sal_Int32 nTarget = std::min(nOpen, nReturn);
591 const OUString& rMailServer, sal_Int16 nPort,
592 const OUString& rConnectionType) :
593 m_sMailServer(rMailServer),
595 m_sConnectionType(rConnectionType)
606 if( rName ==
"ServerName" )
608 else if( rName ==
"Port" )
609 aRet <<= static_cast<sal_Int32>(
m_nPort);
610 else if( rName ==
"ConnectionType" )
640 const OUString& rName,
const OUString& rMimeType) :
660 Sequence<sal_Int8>
aData;
665 aData.realloc(pStream->
TellEnd());
668 pStream->
ReadBytes( pData, aData.getLength() );
677 uno::Sequence< datatransfer::DataFlavor > aRet(1);
685 aRet[0].HumanPresentableName =
m_aName;
692 const datatransfer::DataFlavor& aFlavor )
699 return uno::Reference< beans::XPropertySetInfo >();
709 if ( rPropertyName ==
"URL" )
715 const OUString&,
const uno::Reference< beans::XPropertyChangeListener >& )
721 const uno::Reference< beans::XPropertyChangeListener >& )
727 const uno::Reference< beans::XVetoableChangeListener >& )
733 const uno::Reference< beans::XVetoableChangeListener >& )
782 const uno::Reference< datatransfer::XTransferable >& rBody )
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define LINK(Instance, Class, Member)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
SwMergeAddressItem Next()
exports com.sun.star. mail
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
OUString const & GetMailServer() const
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
SwAddressPreview(std::unique_ptr< weld::ScrolledWindow > xParent)
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
std::unique_ptr< ContentProperties > pData
SwConnectionContext(const OUString &rMailServer, sal_Int16 nPort, const OUString &rConnectionType)
sal_uInt16 nSelectedAddress
bool IsSecureConnection() const
css::uno::Sequence< OUString > m_aCcRecipients
virtual sal_uInt64 TellEnd()
OUString & GetExcludeCountry() const
const StyleSettings & GetStyleSettings() const
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
std::vector< OUString > aAddresses
sal_uInt64 Seek(sal_uInt64 nPos)
sal_uInt16 GetCode() const
const SwDBData & GetCurrentDBData() const
virtual short run() override
sal_Int16 GetMailPort() const
virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
weld::Window * m_pParentWindow
void DrawText_Impl(vcl::RenderContext &rRenderContext, const OUString &rAddress, const Point &rTopLeft, const Size &rSize, bool bIsSelected)
constexpr sal_uInt16 KEY_UP
void SetAddress(const OUString &rAddress)
static OutputDevice * GetDefaultDevice()
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
OUString m_sConnectionType
virtual ~SwConnectionContext() override
virtual ~SwAuthenticator() override
void AddAddress(const OUString &rAddress)
The address string is a list of address elements separated by spaces and breaks.
OUString GetRealFilter() const
const vcl::Font & GetFont() const
Link< LinkParamNone *, void > m_aSelectHdl
css::uno::Sequence< OUString > m_aBccRecipients
virtual bool KeyInput(const KeyEvent &rKEvt) override
virtual OUString SAL_CALL getSubject() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual ~SwAddressPreview() override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
void DrawRect(const tools::Rectangle &rRect)
bool IsAuthentication() const
OUString const & GetInServerPassword() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
constexpr OUStringLiteral aData
sal_Int16 GetInServerPort() const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
constexpr sal_uInt16 KEY_DOWN
exports com.sun.star. datatransfer
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
css::uno::Sequence< OUString > m_aRecipients
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
const Color & GetDisableColor() const
virtual void SAL_CALL disconnected(const css::lang::EventObject &aEvent) override
#define TOOLS_WARN_EXCEPTION(area, stream)
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow &, void)
class SAL_NO_VTABLE XPropertySet
virtual OUString SAL_CALL getUserName() override
OUString m_sSenderAddress
tools::Long Width() const
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
virtual void SAL_CALL addCcRecipient(const OUString &sRecipientAddress) override
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &aFlavor) override
css::uno::Type const & get()
void SelectAddress(sal_uInt16 nSelect)
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
virtual css::uno::Sequence< OUString > SAL_CALL getRecipients() override
virtual ~SwMailMessage() override
bool IsInServerPOP() const
ErrCode GetErrorCode() const
virtual void SAL_CALL addRecipient(const OUString &sRecipientAddress) override
void SetColor(const Color &)
void SetMinLen(sal_uInt16 Len)
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
constexpr sal_uInt16 KEY_RIGHT
virtual css::uno::Sequence< OUString > SAL_CALL getBccRecipients() override
std::size_t ReadBytes(void *pData, std::size_t nSize)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
exports com.sun.star. beans
OUString const & GetInServerUserName() const
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getBody() override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL connected(const css::lang::EventObject &aEvent) override
const vcl::KeyCode & GetKeyCode() const
virtual OUString SAL_CALL getReplyToAddress() override
void RemoveSelectedAddress()
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
OUString m_sReplyToAddress
void SetFont(const vcl::Font &rNewFont)
virtual ~SwMailTransferable() override
void ReplaceSelectedAddress(const OUString &)
virtual void SAL_CALL addBccRecipient(const OUString &sRecipientAddress) override
virtual OUString SAL_CALL getSenderAddress() override
tools::Long AdjustWidth(tools::Long n)
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
SwMailTransferable(const OUString &rURL, const OUString &rName, const OUString &rMimeType)
tools::Long Height() const
virtual css::uno::Sequence< OUString > SAL_CALL getCcRecipients() override
OUString GetPassword() const
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
const Color & GetWindowColor() const
const Point & GetPosPixel() const
bool IsIncludeCountry() const
virtual css::uno::Any SAL_CALL getValueByName(const OUString &Name) override
virtual OUString SAL_CALL getSenderName() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
sal_uInt16 GetSelectedAddress() const
bool IsSMTPAfterPOP() const
std::unique_ptr< SwAddressPreview_Impl > pImpl
virtual void SAL_CALL addAttachment(const css::mail::MailAttachment &aMailAttachment) override
bool CheckMailAddress(const OUString &rMailAddress)
constexpr sal_uInt16 KEY_LEFT
virtual ~SwConnectionListener() override
virtual void SAL_CALL setSubject(const OUString &_subject) override
constexpr OUStringLiteral first
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
OUString const & GetMailPassword() const
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
const Color & GetWindowTextColor() const
void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
OUString const & GetMailUserName() const
virtual OUString SAL_CALL getPassword() override
OUString const & GetInServerName() const
virtual css::uno::Sequence< css::mail::MailAttachment > SAL_CALL getAttachments() override