OSDN Git Service

Send email to multi person success and add CC and TO list
[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 \r
95 int CPatch::Parser(CString &pathfile)\r
96 {\r
97         CString str;\r
98 \r
99         CStdioFile PatchFile;\r
100 \r
101         m_PathFile=pathfile;\r
102         if( ! PatchFile.Open(pathfile,CFile::modeRead) )\r
103                 return -1;\r
104         \r
105         int i=0;\r
106         while(PatchFile.ReadString(str))\r
107         {\r
108                 if(i==1)\r
109                         this->m_Author=str.Right( str.GetLength() - 6 );\r
110                 if(i==2)\r
111                         this->m_Date = str.Right( str.GetLength() - 6 );\r
112                 if(i==3)\r
113                         this->m_Subject = str.Right( str.GetLength() - 8 );\r
114                 if(i==4)\r
115                         break;\r
116                 i++;            \r
117         }\r
118 \r
119         m_Body.resize(PatchFile.GetLength() - PatchFile.GetPosition());\r
120         PatchFile.Read(&m_Body.at(0),PatchFile.GetLength() - PatchFile.GetPosition());\r
121         m_Body.push_back(0);\r
122 \r
123         PatchFile.Close();\r
124 \r
125         g_Git.StringAppend(&m_strBody,&m_Body[0],CP_ACP);\r
126         \r
127         return 0;\r
128 }\r
129 \r
130 void CPatch::GetNameAddress(CString &in, CString &name,CString &address)\r
131 {\r
132         int start,end;\r
133         start=in.Find(_T('<'));\r
134         end=in.Find(_T('>'));\r
135 \r
136         if(start >=0 && end >=0)\r
137         {\r
138                 name=in.Left(start);\r
139                 address=in.Mid(start+1,end-start-1);\r
140         }\r
141         else\r
142                 address=in;\r
143 }\r
144 #if 0\r
145 void CPatch::AddRecipient(CSmtp &mail, CString &tolist, bool isCC)\r
146 {\r
147         int pos=0;\r
148         while(pos>=0)\r
149         {\r
150                 CString one=tolist.Tokenize(_T(";"),pos);\r
151                 int start=one.Find(_T('<'));\r
152                 int end = one.Find(_T('>'));\r
153                 CStringA name;\r
154                 CStringA address;\r
155                 if( start>=0 && end >=0)\r
156                 {\r
157                         name=CUnicodeUtils::GetUTF8(one.Left(start));\r
158                         address=CUnicodeUtils::GetUTF8(one.Mid(start+1,end-start-1));\r
159                         if(address.IsEmpty())\r
160                                 continue;\r
161                         if(isCC)\r
162                                 mail.AddCCRecipient(address,name);\r
163                         else\r
164                                 mail.AddRecipient(address,name);\r
165 \r
166                 }else\r
167                 {\r
168                         if(one.IsEmpty())\r
169                                 continue;\r
170                         if(isCC)\r
171                                 mail.AddCCRecipient(CUnicodeUtils::GetUTF8(one));\r
172                         else\r
173                                 mail.AddRecipient(CUnicodeUtils::GetUTF8(one));\r
174                 }\r
175         }\r
176 }\r
177 #endif