OSDN Git Service

Fix user and password registry type error.
[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 \r
7 CPatch::CPatch()\r
8 {\r
9         \r
10 }\r
11 \r
12 CPatch::~CPatch()\r
13 {\r
14         \r
15 \r
16 }\r
17 \r
18 int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)\r
19 {\r
20         CSmtp mail;\r
21         \r
22         if(mail.GetLastError() != CSMTP_NO_ERROR )\r
23         {\r
24                 return -1;\r
25         }\r
26         \r
27         if(this->Parser(pathfile)       )\r
28                 return -1;\r
29 \r
30 \r
31         CRegString server(REG_SMTP_SERVER);\r
32         CRegDWORD  port(REG_SMTP_PORT,25);\r
33         CRegDWORD  bAuth(REG_SMTP_ISAUTH);\r
34         CRegString  user(REG_SMTP_USER);\r
35         CRegString  password(REG_SMTP_PASSWORD);\r
36 \r
37         mail.SetSMTPServer(CUnicodeUtils::GetUTF8(server),port);\r
38 \r
39         AddRecipient(mail,TO,false);\r
40         AddRecipient(mail,CC,true);\r
41 \r
42         if( bAttachment )\r
43                 mail.AddAttachment(CUnicodeUtils::GetUTF8(pathfile));\r
44 \r
45         CString name,address;\r
46         GetNameAddress(this->m_Author,name,address);\r
47         mail.SetSenderName(CUnicodeUtils::GetUTF8(name));\r
48         mail.SetSenderMail(CUnicodeUtils::GetUTF8(address));\r
49 \r
50         mail.SetXPriority(XPRIORITY_NORMAL);\r
51         mail.SetXMailer("The Bat! (v3.02) Professional");\r
52 \r
53         mail.SetSubject(CUnicodeUtils::GetUTF8(this->m_Subject));\r
54 \r
55         mail.SetMessageBody((char*)&this->m_Body[0]);\r
56 \r
57         if(bAuth)\r
58         {\r
59                 mail.SetLogin(CUnicodeUtils::GetUTF8((CString&)user));\r
60                 mail.SetPassword(CUnicodeUtils::GetUTF8((CString&)password));\r
61         }\r
62 \r
63         return !mail.Send();\r
64 \r
65 }\r
66 \r
67 int CPatch::Parser(CString &pathfile)\r
68 {\r
69         CString str;\r
70 \r
71         CStdioFile PatchFile;\r
72 \r
73         m_PathFile=pathfile;\r
74         if( ! PatchFile.Open(pathfile,CFile::modeRead) )\r
75                 return -1;\r
76         \r
77         int i=0;\r
78         while(PatchFile.ReadString(str))\r
79         {\r
80                 if(i==1)\r
81                         this->m_Author=str.Right( str.GetLength() - 6 );\r
82                 if(i==2)\r
83                         this->m_Date = str.Right( str.GetLength() - 6 );\r
84                 if(i==3)\r
85                         this->m_Subject = str.Right( str.GetLength() - 8 );\r
86                 if(i==4)\r
87                         break;\r
88                 i++;            \r
89         }\r
90 \r
91         m_Body.resize(PatchFile.GetLength() - PatchFile.GetPosition());\r
92         PatchFile.Read(&m_Body.at(0),PatchFile.GetLength() - PatchFile.GetPosition());\r
93 \r
94         PatchFile.Close();\r
95 \r
96 }\r
97 \r
98 void CPatch::GetNameAddress(CString &in, CString &name,CString &address)\r
99 {\r
100         int start,end;\r
101         start=in.Find(_T('<'));\r
102         end=in.Find(_T('>'));\r
103 \r
104         if(start >=0 && end >=0)\r
105         {\r
106                 name=in.Left(start);\r
107                 address=in.Mid(start+1,end-start-1);\r
108         }\r
109         else\r
110                 address=in;\r
111 }\r
112 \r
113 void CPatch::AddRecipient(CSmtp &mail, CString &tolist, bool isCC)\r
114 {\r
115         int pos=0;\r
116         while(pos>=0)\r
117         {\r
118                 CString one=tolist.Tokenize(_T(";"),pos);\r
119                 int start=one.Find(_T('<'));\r
120                 int end = one.Find(_T('>'));\r
121                 CStringA name;\r
122                 CStringA address;\r
123                 if( start>=0 && end >=0)\r
124                 {\r
125                         name=CUnicodeUtils::GetUTF8(one.Left(start));\r
126                         address=CUnicodeUtils::GetUTF8(one.Mid(start+1,end-start-1));\r
127                         if(address.IsEmpty())\r
128                                 continue;\r
129                         if(isCC)\r
130                                 mail.AddCCRecipient(address,name);\r
131                         else\r
132                                 mail.AddRecipient(address,name);\r
133 \r
134                 }else\r
135                 {\r
136                         if(one.IsEmpty())\r
137                                 continue;\r
138                         if(isCC)\r
139                                 mail.AddCCRecipient(CUnicodeUtils::GetUTF8(one));\r
140                         else\r
141                                 mail.AddRecipient(CUnicodeUtils::GetUTF8(one));\r
142                 }\r
143         }\r
144 }