1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2011 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.
25 #include "unicodeutils.h"
39 void CPatch::ConvertToArray(CString
&to
,CStringArray
&Array
)
44 CString str
=to
.Tokenize(_T(";"),start
);
50 int CPatch::Send(CString
&pathfile
,CString
&TO
,CString
&CC
,bool bAttachment
, bool useMAPI
)
52 if(this->Parser(pathfile
))
56 CStringArray attachments
;
59 attachments
.Add(pathfile
);
63 body
= this->m_strBody
;
66 CString errortext
= _T("");
67 int ret
= SendMail(TO
, CC
, this->m_Subject
, body
, attachments
, useMAPI
, &errortext
);
68 this->m_LastError
=errortext
;
72 int CPatch::SendPatchesCombined(CTGitPathList
&list
,CString
&To
,CString
&CC
, CString
&subject
,bool bAttachment
, bool useMAPI
,CString
*errortext
)
74 CStringArray attachments
;
76 for(int i
=0;i
<list
.GetCount();i
++)
79 patch
.Parser((CString
&)list
[i
].GetWinPathString());
82 attachments
.Add(list
[i
].GetWinPathString());
83 body
+=patch
.m_Subject
;
88 g_Git
.StringAppend(&body
,(BYTE
*)patch
.m_Body
.GetBuffer(),CP_ACP
,patch
.m_Body
.GetLength());
92 return SendMail(To
, CC
, subject
, body
, attachments
, useMAPI
, errortext
);
95 int CPatch::SendMail(CString
&To
, CString
&CC
, CString
&subject
, CString
&body
, CStringArray
&attachments
, bool useMAPI
, CString
*errortext
)
98 sender
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
103 BOOL bMAPIInit
= mapiSender
.MAPIInitialize();
107 *errortext
= mapiSender
.GetLastErrorMsg();
111 mapiSender
.SetShowComposeDialog(TRUE
);
112 mapiSender
.SetFrom(g_Git
.GetUserEmail());
113 mapiSender
.SetTo(To
);
115 mapiSender
.AddCC(CC
);
116 mapiSender
.SetSubject(subject
);
117 mapiSender
.SetMessage(body
);
118 for(int i
=0; i
< attachments
.GetSize(); i
++)
120 mapiSender
.AddAttachment(attachments
[i
]);
123 BOOL bSend
= mapiSender
.Send();
129 *errortext
= mapiSender
.GetLastErrorMsg();
136 if(mail
.SendSpeedEmail(sender
,To
,subject
,body
,NULL
,&attachments
,CC
,25,sender
))
141 *errortext
=mail
.GetLastErrorText();
147 int CPatch::Parser(CString
&pathfile
)
154 if( ! PatchFile
.Open(pathfile
,CFile::modeRead
) )
161 PatchFile
.ReadString(str
);
163 this->m_Author
=str
.Right( str
.GetLength() - 6 );
165 this->m_Date
= str
.Right( str
.GetLength() - 6 );
167 this->m_Subject
= str
.Right( str
.GetLength() - 8 );
172 LONGLONG offset
=PatchFile
.GetPosition();
174 PatchFile
.Read(m_Body
.GetBuffer(PatchFile
.GetLength()),PatchFile
.GetLength());
175 m_Body
.ReleaseBuffer();
180 one
=m_Body
.Tokenize("\n",start
);
182 one
=m_Body
.Tokenize("\n",start
);
183 if(one
.GetLength()>6)
184 g_Git
.StringAppend(&m_Author
,(BYTE
*)one
.GetBuffer()+6,CP_ACP
,one
.GetLength()-6);
186 one
=m_Body
.Tokenize("\n",start
);
187 if(one
.GetLength()>6)
188 g_Git
.StringAppend(&m_Date
,(BYTE
*)one
.GetBuffer()+6,CP_ACP
,one
.GetLength()-6);
190 one
=m_Body
.Tokenize("\n",start
);
191 if(one
.GetLength()>9)
192 g_Git
.StringAppend(&m_Subject
,(BYTE
*)one
.GetBuffer()+9,CP_ACP
,one
.GetLength()-9);
194 //one=m_Body.Tokenize("\n",start);
196 g_Git
.StringAppend(&m_strBody
,(BYTE
*)m_Body
.GetBuffer()+start
+1,CP_ACP
,m_Body
.GetLength()-start
-1);
201 void CPatch::GetNameAddress(CString
&in
, CString
&name
,CString
&address
)
204 start
=in
.Find(_T('<'));
205 end
=in
.Find(_T('>'));
207 if(start
>=0 && end
>=0)
210 address
=in
.Mid(start
+1,end
-start
-1);