OSDN Git Service

d479e41c37778baf69df1b4ba4d7179b84d9a95f
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Patch.cpp
1 #include "StdAfx.h"\r
2 #include "Patch.h"\r
3 #include "csmtp.h"\r
4 #include "registry.h"\r
5 #include "unicodeutils.h"\r
6 #include "hwsmtp.h"\r
7 #include "Windns.h"\r
8 #include "Git.h"\r
9 \r
10 CPatch::CPatch()\r
11 {\r
12         \r
13 }\r
14 \r
15 CPatch::~CPatch()\r
16 {\r
17         \r
18 \r
19 }\r
20 \r
21 void CPatch::ConvertToArray(CString &to,CStringArray &Array)\r
22 {\r
23         int start=0;\r
24         while(start>=0)\r
25         {\r
26                 CString str=to.Tokenize(_T(";"),start);\r
27                 if(!str.IsEmpty())\r
28                         Array.Add(str);\r
29         }\r
30 }\r
31 \r
32 int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)\r
33 {\r
34         CHwSMTP mail;\r
35         if(this->Parser(pathfile)       )\r
36                 return -1;\r
37 \r
38         CStringArray attachments,CCArray;\r
39         if(bAttachment)\r
40         {\r
41                 attachments.Add(pathfile);\r
42         }\r
43         \r
44         //ConvertToArray(CC,CCArray);\r
45 \r
46         CString sender;\r
47         sender.Format(_T("%s <%s> "),g_Git.GetUserName(),g_Git.GetUserEmail());\r
48 \r
49         if(mail.SendSpeedEmail(this->m_Author,TO,this->m_Subject,this->m_strBody,NULL,&attachments,CC,25,sender))\r
50                 return 0;\r
51         else\r
52         {\r
53                 this->m_LastError=mail.GetLastErrorText();\r
54                 return -1;\r
55         }\r
56 #if 0\r
57         CRegString server(REG_SMTP_SERVER);\r
58         CRegDWORD  port(REG_SMTP_PORT,25);\r
59         CRegDWORD  bAuth(REG_SMTP_ISAUTH);\r
60         CRegString  user(REG_SMTP_USER);\r
61         CRegString  password(REG_SMTP_PASSWORD);\r
62 \r
63         mail.SetSMTPServer(CUnicodeUtils::GetUTF8(server),port);\r
64 \r
65         AddRecipient(mail,TO,false);\r
66         AddRecipient(mail,CC,true);\r
67 \r
68         if( bAttachment )\r
69                 mail.AddAttachment(CUnicodeUtils::GetUTF8(pathfile));\r
70 \r
71         CString name,address;\r
72         GetNameAddress(this->m_Author,name,address);\r
73         mail.SetSenderName(CUnicodeUtils::GetUTF8(name));\r
74         mail.SetSenderMail(CUnicodeUtils::GetUTF8(address));\r
75 \r
76         mail.SetXPriority(XPRIORITY_NORMAL);\r
77         mail.SetXMailer("The Bat! (v3.02) Professional");\r
78 \r
79         mail.SetSubject(CUnicodeUtils::GetUTF8(this->m_Subject));\r
80 \r
81         mail.SetMessageBody((char*)&this->m_Body[0]);\r
82 \r
83         if(bAuth)\r
84         {\r
85                 mail.SetLogin(CUnicodeUtils::GetUTF8((CString&)user));\r
86                 mail.SetPassword(CUnicodeUtils::GetUTF8((CString&)password));\r
87         }\r
88 \r
89         return !mail.Send();\r
90 #endif\r
91 \r
92 \r
93 }\r
94 int CPatch::Send(CTGitPathList &list,CString &To,CString &CC, CString &subject,bool bAttachment,CString *errortext)\r
95 {\r
96         CStringArray attachments;\r
97         CString body;\r
98         for(int i=0;i<list.GetCount();i++)\r
99         {\r
100                 CPatch patch;\r
101                 patch.Parser((CString&)list[i].GetWinPathString());\r
102                 if(bAttachment)\r
103                 {\r
104                         attachments.Add(list[i].GetWinPathString());\r
105                         body+=patch.m_Subject;\r
106                         body+=_T("\r\n");\r
107 \r
108                 }else\r
109                 {\r
110                         g_Git.StringAppend(&body,(BYTE*)patch.m_Body.GetBuffer(),CP_ACP,patch.m_Body.GetLength());\r
111                 }\r
112 \r
113         }\r
114 \r
115         CHwSMTP mail;\r
116         \r
117         CString sender;\r
118         sender.Format(_T("%s <%s> "),g_Git.GetUserName(),g_Git.GetUserEmail());\r
119 \r
120         if(mail.SendSpeedEmail(sender,To,subject,body,NULL,&attachments,CC,25,sender))\r
121                 return 0;\r
122         else\r
123         {\r
124                 if(errortext)\r
125                         *errortext=mail.GetLastErrorText();\r
126                 return -1;\r
127         }\r
128 \r
129 }\r
130 \r
131 int CPatch::Parser(CString &pathfile)\r
132 {\r
133         CString str;\r
134 \r
135         CStdioFile PatchFile;\r
136 \r
137         m_PathFile=pathfile;\r
138         if( ! PatchFile.Open(pathfile,CFile::modeRead) )\r
139                 return -1;\r
140         \r
141         int i=0;\r
142 #if 0\r
143         while(i<4)\r
144         {   PatchFile.ReadString(str);\r
145                 if(i==1)\r
146                         this->m_Author=str.Right( str.GetLength() - 6 );\r
147                 if(i==2)\r
148                         this->m_Date = str.Right( str.GetLength() - 6 );\r
149                 if(i==3)\r
150                         this->m_Subject = str.Right( str.GetLength() - 8 );\r
151                 \r
152                 i++;            \r
153         }\r
154 \r
155         LONGLONG offset=PatchFile.GetPosition();\r
156 #endif\r
157         PatchFile.Read(m_Body.GetBufferSetLength(PatchFile.GetLength()),PatchFile.GetLength());\r
158         PatchFile.Close();\r
159 \r
160         int start=0;\r
161         CStringA one;\r
162         one=m_Body.Tokenize("\n",start);\r
163 \r
164         one=m_Body.Tokenize("\n",start);\r
165         if(one.GetLength()>6)\r
166                 g_Git.StringAppend(&m_Author,(BYTE*)one.GetBuffer()+6,CP_ACP,one.GetLength()-6);\r
167 \r
168         one=m_Body.Tokenize("\n",start);\r
169         if(one.GetLength()>6)\r
170                 g_Git.StringAppend(&m_Date,(BYTE*)one.GetBuffer()+6,CP_ACP,one.GetLength()-6);\r
171 \r
172         one=m_Body.Tokenize("\n",start);\r
173         if(one.GetLength()>8)\r
174                 g_Git.StringAppend(&m_Subject,(BYTE*)one.GetBuffer()+8,CP_ACP,one.GetLength()-8);\r
175 \r
176         //one=m_Body.Tokenize("\n",start);\r
177         \r
178         g_Git.StringAppend(&m_strBody,(BYTE*)m_Body.GetBuffer()+start+1,CP_ACP,m_Body.GetLength()-start-1);\r
179         \r
180         return 0;\r
181 }\r
182 \r
183 void CPatch::GetNameAddress(CString &in, CString &name,CString &address)\r
184 {\r
185         int start,end;\r
186         start=in.Find(_T('<'));\r
187         end=in.Find(_T('>'));\r
188 \r
189         if(start >=0 && end >=0)\r
190         {\r
191                 name=in.Left(start);\r
192                 address=in.Mid(start+1,end-start-1);\r
193         }\r
194         else\r
195                 address=in;\r
196 }\r
197 #if 0\r
198 void CPatch::AddRecipient(CSmtp &mail, CString &tolist, bool isCC)\r
199 {\r
200         int pos=0;\r
201         while(pos>=0)\r
202         {\r
203                 CString one=tolist.Tokenize(_T(";"),pos);\r
204                 int start=one.Find(_T('<'));\r
205                 int end = one.Find(_T('>'));\r
206                 CStringA name;\r
207                 CStringA address;\r
208                 if( start>=0 && end >=0)\r
209                 {\r
210                         name=CUnicodeUtils::GetUTF8(one.Left(start));\r
211                         address=CUnicodeUtils::GetUTF8(one.Mid(start+1,end-start-1));\r
212                         if(address.IsEmpty())\r
213                                 continue;\r
214                         if(isCC)\r
215                                 mail.AddCCRecipient(address,name);\r
216                         else\r
217                                 mail.AddRecipient(address,name);\r
218 \r
219                 }else\r
220                 {\r
221                         if(one.IsEmpty())\r
222                                 continue;\r
223                         if(isCC)\r
224                                 mail.AddCCRecipient(CUnicodeUtils::GetUTF8(one));\r
225                         else\r
226                                 mail.AddRecipient(CUnicodeUtils::GetUTF8(one));\r
227                 }\r
228         }\r
229 }\r
230 #endif