Re-integrate the GPG signed commit into the unit tests
[TortoiseGit.git] / src / TortoiseProc / SendMailPatch.cpp
blob59251f685aed1771a505df2db94e13ee0d27d881
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016 - 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.
21 #include "stdafx.h"
22 #include "SendMailPatch.h"
23 #include "SerialPatch.h"
25 CSendMailPatch::CSendMailPatch(const CString& To, const CString& CC, const CString& subject, bool bAttachment, bool bCombine)
26 : CSendMailCombineable(To, CC, subject, bAttachment, bCombine)
30 CSendMailPatch::~CSendMailPatch()
34 int CSendMailPatch::SendAsSingleMail(const CTGitPath& path, CGitProgressList* instance)
36 ASSERT(instance);
38 CString pathfile(path.GetWinPathString());
39 CSerialPatch patch;
40 if (patch.Parse(pathfile, !m_bAttachment))
42 instance->ReportError(L"Could not open/parse " + pathfile);
43 return -2;
46 CString body;
47 CStringArray attachments;
48 if (m_bAttachment)
49 attachments.Add(pathfile);
50 else
51 body = patch.m_strBody;
53 return SendMail(path, instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, patch.m_Subject, body, attachments);
56 int CSendMailPatch::SendAsCombinedMail(const CTGitPathList &list, CGitProgressList* instance)
58 ASSERT(instance);
60 CStringArray attachments;
61 CString body;
62 for (int i = 0; i < list.GetCount(); ++i)
64 CSerialPatch patch;
65 if (patch.Parse((CString&)list[i].GetWinPathString(), !m_bAttachment))
67 instance->ReportError(L"Could not open/parse " + list[i].GetWinPathString());
68 return -2;
70 if (m_bAttachment)
72 attachments.Add(list[i].GetWinPathString());
73 body += patch.m_Subject;
74 body += L"\r\n";
76 else
78 try
80 CGit::StringAppend(&body, (BYTE*)(LPCSTR)patch.m_Body, CP_UTF8, patch.m_Body.GetLength());
82 catch (CMemoryException *)
84 instance->ReportError(L"Out of memory. Could not parse " + list[i].GetWinPathString());
85 return -2;
89 return SendMail(CTGitPath(), instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, m_sSubject, body, attachments);