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.
24 CSendMailPatch::CSendMailPatch(CString
&To
, CString
&CC
, CString
&subject
, bool bAttachment
, bool bCombine
)
25 : CSendMailCombineable(To
, CC
, subject
, bAttachment
, bCombine
)
29 CSendMailPatch::~CSendMailPatch()
33 int CSendMailPatch::SendAsSingleMail(CTGitPath
&path
, CGitProgressList
* instance
)
37 CString
pathfile(path
.GetWinPathString());
39 if (patch
.Parse(pathfile
))
41 instance
->ReportError(_T("Could not open/parse ") + pathfile
);
46 CStringArray attachments
;
48 attachments
.Add(pathfile
);
50 body
= patch
.m_strBody
;
52 return SendMail(path
, instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, patch
.m_Subject
, body
, attachments
);
55 int CSendMailPatch::SendAsCombinedMail(CTGitPathList
&list
, CGitProgressList
* instance
)
59 CStringArray attachments
;
61 for (int i
= 0; i
< list
.GetCount(); ++i
)
64 if (patch
.Parse((CString
&)list
[i
].GetWinPathString()))
66 instance
->ReportError(_T("Could not open/parse ") + list
[i
].GetWinPathString());
71 attachments
.Add(list
[i
].GetWinPathString());
72 body
+= patch
.m_Subject
;
79 g_Git
.StringAppend(&body
, (BYTE
*)patch
.m_Body
.GetBuffer(), CP_UTF8
, patch
.m_Body
.GetLength());
81 catch (CMemoryException
*)
83 instance
->ReportError(_T("Out of memory. Could not parse ") + list
[i
].GetWinPathString());
88 return SendMail(CTGitPath(), instance
, m_sSenderName
, m_sSenderMail
, m_sTo
, m_sCC
, m_sSubject
, body
, attachments
);
99 int CPatch::Parse(CString
&pathfile
)
103 m_PathFile
= pathfile
;
107 if (!PatchFile
.Open(m_PathFile
, CFile::modeRead
))
110 PatchFile
.Read(m_Body
.GetBuffer((UINT
)PatchFile
.GetLength()), (UINT
)PatchFile
.GetLength());
111 m_Body
.ReleaseBuffer();
118 one
=m_Body
.Tokenize("\n",start
);
122 one
=m_Body
.Tokenize("\n",start
);
123 if(one
.GetLength()>6)
124 g_Git
.StringAppend(&m_Author
, (BYTE
*)one
.GetBuffer() + 6, CP_UTF8
, one
.GetLength() - 6);
128 one
=m_Body
.Tokenize("\n",start
);
129 if(one
.GetLength()>6)
130 g_Git
.StringAppend(&m_Date
, (BYTE
*)one
.GetBuffer() + 6, CP_UTF8
, one
.GetLength() - 6);
134 one
=m_Body
.Tokenize("\n",start
);
135 if(one
.GetLength()>9)
137 g_Git
.StringAppend(&m_Subject
, (BYTE
*)one
.GetBuffer() + 9, CP_UTF8
, one
.GetLength() - 9);
138 while (m_Body
.GetLength() > start
&& m_Body
.GetAt(start
) == _T(' '))
140 one
= m_Body
.Tokenize("\n", start
);
141 g_Git
.StringAppend(&m_Subject
, (BYTE
*)one
.GetBuffer(), CP_UTF8
, one
.GetLength());
145 if (start
+ 1 < m_Body
.GetLength())
146 g_Git
.StringAppend(&m_strBody
, (BYTE
*)m_Body
.GetBuffer() + start
+ 1, CP_UTF8
, m_Body
.GetLength() - start
- 1);