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
, bool useMAPI
)
31 m_sSenderName
= g_Git
.GetUserName();
32 m_sSenderMail
= g_Git
.GetUserEmail();
36 m_bAttachment
= bAttachment
;
39 CSendMail::~CSendMail(void)
43 int CSendMail::SendMail(const CTGitPath
&item
, CGitProgressList
* instance
, CString
&FromName
, CString
&FromMail
, CString
&To
, CString
&CC
, CString
&subject
, CString
&body
, CStringArray
&attachments
, bool useMAPI
)
49 if (instance
->IsCancelled() == TRUE
)
51 instance
->ReportUserCanceled();
55 instance
->Notify(item
, git_wc_notify_sendmail
);
58 if (SendMail(FromName
, FromMail
, To
, CC
, subject
, body
, attachments
, useMAPI
, &error
) == 0)
61 instance
->ReportError(error
);
63 if (instance
->IsCancelled() == FALSE
) // do not retry/sleep if the user already canceled
69 retry
.LoadString(IDS_SVNACTION_SENDMAIL_RETRY
);
70 instance
->ReportNotification(retry
);
78 int CSendMail::SendMail(CString
&FromName
, CString
&FromMail
, CString
&To
, CString
&CC
, CString
&subject
, CString
&body
, CStringArray
&attachments
, bool useMAPI
, CString
*errortext
)
83 BOOL bMAPIInit
= mapiSender
.MAPIInitialize();
87 *errortext
= mapiSender
.GetLastErrorMsg();
91 mapiSender
.SetShowComposeDialog(TRUE
);
92 mapiSender
.SetFrom(FromName
);
96 mapiSender
.SetSubject(subject
);
97 mapiSender
.SetMessage(body
);
98 for (int i
= 0; i
< attachments
.GetSize(); ++i
)
99 mapiSender
.AddAttachment(attachments
[i
]);
101 BOOL bSend
= mapiSender
.Send();
107 *errortext
= mapiSender
.GetLastErrorMsg();
114 sender
.Format(_T("%s <%s>"), FromName
, FromMail
);
117 if (mail
.SendSpeedEmail(sender
, To
, subject
, body
, NULL
, &attachments
, CC
, 25, sender
))
122 *errortext
= mail
.GetLastErrorText();
128 CSendMailCombineable::CSendMailCombineable(CString
&To
, CString
&CC
, CString
&subject
, bool bAttachment
, bool bCombine
, bool useMAPI
)
129 : CSendMail(To
, CC
, bAttachment
, useMAPI
)
130 , m_sSubject(subject
)
131 , m_bCombine(bCombine
)
135 CSendMailCombineable::~CSendMailCombineable()
139 int CSendMailCombineable::Send(CTGitPathList
&list
, CGitProgressList
* instance
)
143 return SendAsCombinedMail(list
, instance
);
147 instance
->SetItemCountTotal(list
.GetCount() + 1);
148 for (int i
= 0; i
< list
.GetCount(); ++i
)
150 instance
->SetItemProgress(i
);
151 if (SendAsSingleMail((CTGitPath
&)list
[i
], instance
))
154 instance
->SetItemProgress(list
.GetCount() + 1);
160 int GetFileContents(CString
&filename
, CString
&content
)
163 if (file
.Open(filename
, CFile::modeRead
))
166 while (file
.ReadString(str
))
178 int CSendMailCombineable::SendAsSingleMail(CTGitPath
&path
, CGitProgressList
* instance
)
182 CString
pathfile(path
.GetWinPathString());
185 CStringArray attachments
;
187 attachments
.Add(pathfile
);
188 else if (GetFileContents(pathfile
, body
))
190 instance
->ReportError(_T("Could not open ") + pathfile
);
194 return SendMail(path
, instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
, m_bUseMAPI
);
197 int CSendMailCombineable::SendAsCombinedMail(CTGitPathList
&list
, CGitProgressList
* instance
)
201 CStringArray attachments
;
203 for (int i
= 0; i
< list
.GetCount(); ++i
)
207 attachments
.Add(list
[i
].GetWinPathString());
211 CString
filename(list
[i
].GetWinPathString());
212 body
+= filename
+ _T(":\n");
213 if (GetFileContents(filename
, body
))
215 instance
->ReportError(_T("Could not open ") + filename
);
221 return SendMail(CTGitPath(), instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
, m_bUseMAPI
);