1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 CSendMail::CSendMail(const CString
& To
, const CString
& CC
, bool bAttachment
)
30 m_sSenderName
= g_Git
.GetUserName();
31 m_sSenderMail
= g_Git
.GetUserEmail();
34 m_bAttachment
= bAttachment
;
37 CSendMail::~CSendMail(void)
41 int CSendMail::SendMail(const CTGitPath
&item
, CGitProgressList
* instance
, const CString
& FromName
, const CString
& FromMail
, const CString
& To
, const CString
& CC
, const CString
&subject
, const CString
& body
, CStringArray
&attachments
)
47 if (instance
->IsCancelled() == TRUE
)
49 instance
->ReportUserCanceled();
53 instance
->AddNotify(new CGitProgressList::NotificationData(item
, IDS_SVNACTION_SENDMAIL_START
), CColors::Modified
);
56 if (SendMail(FromName
, FromMail
, To
, CC
, subject
, body
, attachments
, &error
) == 0)
59 instance
->ReportError(error
);
61 if (instance
->IsCancelled() == FALSE
) // do not retry/sleep if the user already canceled
67 temp
.LoadString(IDS_SVNACTION_SENDMAIL_RETRY
);
68 instance
->ReportNotification(temp
);
76 int CSendMail::SendMail(const CString
& FromName
, const CString
& FromMail
, const CString
& To
, const CString
& CC
, const CString
& subject
, const CString
& body
, CStringArray
&attachments
, CString
*errortext
)
78 if (CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType"), SEND_MAIL_MAPI
) == SEND_MAIL_MAPI
)
81 BOOL bMAPIInit
= mapiSender
.MAPIInitialize();
85 *errortext
= mapiSender
.GetLastErrorMsg();
89 mapiSender
.SetShowComposeDialog(TRUE
);
90 mapiSender
.SetFrom(FromMail
, FromName
);
94 mapiSender
.SetSubject(subject
);
95 mapiSender
.SetMessage(body
);
96 for (int i
= 0; i
< attachments
.GetSize(); ++i
)
97 mapiSender
.AddAttachment(attachments
[i
]);
99 BOOL bSend
= mapiSender
.Send();
105 *errortext
= mapiSender
.GetLastErrorMsg();
112 sender
.Format(_T("%s <%s>"), (LPCTSTR
)CHwSMTP::GetEncodedHeader(FromName
), (LPCTSTR
)FromMail
);
115 if (CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType"), SEND_MAIL_SMTP_CONFIGURED
) == SEND_MAIL_SMTP_CONFIGURED
)
117 CString
recipients(To
);
119 recipients
+= L
";" + CC
;
120 if (mail
.SendEmail((CString
)CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Address"), _T("")), (CString
)CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Username"), _T("")), (CString
)CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Password"), _T("")), (BOOL
)CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\AuthenticationRequired"), FALSE
), sender
, recipients
, subject
, body
, nullptr, &attachments
, CC
, (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Port"), 25), sender
, To
, (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Encryption"), 0)) == TRUE
)
125 *errortext
= mail
.GetLastErrorText();
129 else if (mail
.SendSpeedEmail(sender
, To
, subject
, body
, nullptr, &attachments
, CC
, sender
))
134 *errortext
= mail
.GetLastErrorText();
140 CSendMailCombineable::CSendMailCombineable(const CString
& To
, const CString
& CC
, const CString
& subject
, bool bAttachment
, bool bCombine
)
141 : CSendMail(To
, CC
, bAttachment
)
142 , m_sSubject(subject
)
143 , m_bCombine(bCombine
)
147 CSendMailCombineable::~CSendMailCombineable()
151 int CSendMailCombineable::Send(const CTGitPathList
& list
, CGitProgressList
* instance
)
154 return SendAsCombinedMail(list
, instance
);
157 instance
->SetItemCountTotal(list
.GetCount() + 1);
158 for (int i
= 0; i
< list
.GetCount(); ++i
)
160 instance
->SetItemProgress(i
);
161 if (SendAsSingleMail((CTGitPath
&)list
[i
], instance
))
164 instance
->SetItemProgress(list
.GetCount() + 1);
170 int GetFileContents(CString
&filename
, CString
&content
)
173 if (file
.Open(filename
, CFile::modeRead
))
176 while (file
.ReadString(str
))
188 int CSendMailCombineable::SendAsSingleMail(const CTGitPath
& path
, CGitProgressList
* instance
)
192 CString
pathfile(path
.GetWinPathString());
195 CStringArray attachments
;
197 attachments
.Add(pathfile
);
198 else if (GetFileContents(pathfile
, body
))
200 instance
->ReportError(_T("Could not open ") + pathfile
);
204 return SendMail(path
, instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
);
207 int CSendMailCombineable::SendAsCombinedMail(const CTGitPathList
&list
, CGitProgressList
* instance
)
211 CStringArray attachments
;
213 for (int i
= 0; i
< list
.GetCount(); ++i
)
216 attachments
.Add(list
[i
].GetWinPathString());
219 CString
filename(list
[i
].GetWinPathString());
220 body
+= filename
+ _T(":\n");
221 if (GetFileContents(filename
, body
))
223 instance
->ReportError(_T("Could not open ") + filename
);
229 return SendMail(CTGitPath(), instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
);