tdf#116234 Apply email settings just set

Email configuration that is entered in the SwMailConfigDlg
dialog is written to the (global) configuration, while
the existing SwMailMergeConfig item 'xConfigItem'
was not updated, so the newly entered values for
the email server connection weren't applied for
the current mail merge previously.

In order to have them take effect, take over the
new settings to 'xConfigItem' from the global
config where those were just set.

Change-Id: If0dae3ce26af797ffa728dca96f08dce3197557c
Reviewed-on: https://gerrit.libreoffice.org/79847
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/sw/source/ui/dbui/mmresultdialogs.cxx b/sw/source/ui/dbui/mmresultdialogs.cxx
index ef96c5b..2b7d5e2a 100644
--- a/sw/source/ui/dbui/mmresultdialogs.cxx
+++ b/sw/source/ui/dbui/mmresultdialogs.cxx
@@ -124,6 +124,35 @@ static OUString lcl_GetColumnValueOf(const OUString& rColumn, Reference < contai
    return sRet;
}

/**
 * Replace email server settings in rConfigItem with those set in Writer's global
 * mail merge config settings.
 */
static void lcl_UpdateEmailSettingsFromGlobalConfig(SwMailMergeConfigItem& rConfigItem)
{
    // newly created SwMailMergeConfigItem is initialized with values from (global) config
    SwMailMergeConfigItem aConfigItem;

    // take over email-related settings
    rConfigItem.SetMailDisplayName(aConfigItem.GetMailDisplayName());
    rConfigItem.SetMailAddress(aConfigItem.GetMailAddress());
    rConfigItem.SetMailReplyTo(aConfigItem.GetMailReplyTo());
    rConfigItem.SetMailReplyTo(aConfigItem.IsMailReplyTo());
    rConfigItem.SetMailServer(aConfigItem.GetMailServer());
    rConfigItem.SetMailPort(aConfigItem.GetMailPort());
    rConfigItem.SetSecureConnection(aConfigItem.IsSecureConnection());
    // authentication settings
    rConfigItem.SetAuthentication(aConfigItem.IsAuthentication());
    rConfigItem.SetSMTPAfterPOP(aConfigItem.IsSMTPAfterPOP());
    rConfigItem.SetMailUserName(aConfigItem.GetMailUserName());
    rConfigItem.SetMailPassword(aConfigItem.GetMailPassword());
    rConfigItem.SetInServerName(aConfigItem.GetInServerName());
    rConfigItem.SetInServerPort(aConfigItem.GetInServerPort());
    rConfigItem.SetInServerPOP(aConfigItem.IsInServerPOP());
    rConfigItem.SetInServerUserName(aConfigItem.GetInServerUserName());
    rConfigItem.SetInServerPassword(aConfigItem.GetInServerPassword());
}

class SwSaveWarningBox_Impl : public SwMessageAndEditDialog
{
    DECL_LINK( ModifyHdl, weld::Entry&, void);
@@ -856,6 +885,10 @@ IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, voi

        if(nRet != RET_OK && nRet != RET_YES)
            return; // back to the dialog

        // SwMailConfigDlg writes mail merge email settings only to (global) config,
        // so copy them to the existing config item
        lcl_UpdateEmailSettingsFromGlobalConfig(*xConfigItem.get());
    }
    //add the documents
    sal_uInt32 nBegin = 0;