1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2011-2013 Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 CSendMail::CSendMail(CString
&To
, CString
&CC
, bool bAttachment
)
31 m_sSenderName
= g_Git
.GetUserName();
32 m_sSenderMail
= g_Git
.GetUserEmail();
35 m_bAttachment
= bAttachment
;
38 CSendMail::~CSendMail(void)
42 int CSendMail::SendMail(const CTGitPath
&item
, CGitProgressList
* instance
, CString
&FromName
, CString
&FromMail
, CString
&To
, CString
&CC
, CString
&subject
, CString
&body
, CStringArray
&attachments
)
48 if (instance
->IsCancelled() == TRUE
)
50 instance
->ReportUserCanceled();
54 instance
->AddNotify(new CGitProgressList::NotificationData(item
, IDS_SVNACTION_SENDMAIL_START
), CColors::Modified
);
57 if (SendMail(FromName
, FromMail
, To
, CC
, subject
, body
, attachments
, &error
) == 0)
60 instance
->ReportError(error
);
62 if (instance
->IsCancelled() == FALSE
) // do not retry/sleep if the user already canceled
68 retry
.LoadString(IDS_SVNACTION_SENDMAIL_RETRY
);
69 instance
->ReportNotification(retry
);
77 int CSendMail::SendMail(CString
&FromName
, CString
&FromMail
, CString
&To
, CString
&CC
, CString
&subject
, CString
&body
, CStringArray
&attachments
, CString
*errortext
)
79 if (CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType"), 1) == 1)
82 BOOL bMAPIInit
= mapiSender
.MAPIInitialize();
86 *errortext
= mapiSender
.GetLastErrorMsg();
90 mapiSender
.SetShowComposeDialog(TRUE
);
91 mapiSender
.SetFrom(FromName
);
95 mapiSender
.SetSubject(subject
);
96 mapiSender
.SetMessage(body
);
97 for (int i
= 0; i
< attachments
.GetSize(); ++i
)
98 mapiSender
.AddAttachment(attachments
[i
]);
100 BOOL bSend
= mapiSender
.Send();
106 *errortext
= mapiSender
.GetLastErrorMsg();
113 sender
.Format(_T("%s <%s>"), FromName
, FromMail
);
116 if (CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType"), 2) == 2)
118 CString
recipients(To
);
120 recipients
+= L
";" + CC
;
121 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
)
126 *errortext
= mail
.GetLastErrorText();
130 else if (mail
.SendSpeedEmail(sender
, To
, subject
, body
, nullptr, &attachments
, CC
, sender
))
135 *errortext
= mail
.GetLastErrorText();
141 CSendMailCombineable::CSendMailCombineable(CString
&To
, CString
&CC
, CString
&subject
, bool bAttachment
, bool bCombine
)
142 : CSendMail(To
, CC
, bAttachment
)
143 , m_sSubject(subject
)
144 , m_bCombine(bCombine
)
148 CSendMailCombineable::~CSendMailCombineable()
152 int CSendMailCombineable::Send(CTGitPathList
&list
, CGitProgressList
* instance
)
156 return SendAsCombinedMail(list
, instance
);
160 instance
->SetItemCountTotal(list
.GetCount() + 1);
161 for (int i
= 0; i
< list
.GetCount(); ++i
)
163 instance
->SetItemProgress(i
);
164 if (SendAsSingleMail((CTGitPath
&)list
[i
], instance
))
167 instance
->SetItemProgress(list
.GetCount() + 1);
173 int GetFileContents(CString
&filename
, CString
&content
)
176 if (file
.Open(filename
, CFile::modeRead
))
179 while (file
.ReadString(str
))
191 int CSendMailCombineable::SendAsSingleMail(CTGitPath
&path
, CGitProgressList
* instance
)
195 CString
pathfile(path
.GetWinPathString());
198 CStringArray attachments
;
200 attachments
.Add(pathfile
);
201 else if (GetFileContents(pathfile
, body
))
203 instance
->ReportError(_T("Could not open ") + pathfile
);
207 return SendMail(path
, instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
);
210 int CSendMailCombineable::SendAsCombinedMail(CTGitPathList
&list
, CGitProgressList
* instance
)
214 CStringArray attachments
;
216 for (int i
= 0; i
< list
.GetCount(); ++i
)
220 attachments
.Add(list
[i
].GetWinPathString());
224 CString
filename(list
[i
].GetWinPathString());
225 body
+= filename
+ _T(":\n");
226 if (GetFileContents(filename
, body
))
228 instance
->ReportError(_T("Could not open ") + filename
);
234 return SendMail(CTGitPath(), instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
);