OSDN Git Service

Send Attachment successfully
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Patch.cpp
index 7ba59eb..7bebda9 100644 (file)
@@ -3,6 +3,9 @@
 #include "csmtp.h"\r
 #include "registry.h"\r
 #include "unicodeutils.h"\r
+#include "hwsmtp.h"\r
+#include "Windns.h"\r
+#include "Git.h"\r
 \r
 CPatch::CPatch()\r
 {\r
@@ -15,6 +18,17 @@ CPatch::~CPatch()
 \r
 }\r
 \r
+void CPatch::ConvertToArray(CString &to,CStringArray &Array)\r
+{\r
+       int start=0;\r
+       while(start>=0)\r
+       {\r
+               CString str=to.Tokenize(_T(";"),start);\r
+               if(!str.IsEmpty())\r
+                       Array.Add(str);\r
+       }\r
+}\r
+\r
 int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)\r
 {\r
        CSmtp mail;\r
@@ -27,12 +41,42 @@ int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)
        if(this->Parser(pathfile)       )\r
                return -1;\r
 \r
+       int at=TO.Find(_T('@'));\r
+       int start =0;\r
+       TO = TO.Tokenize(_T(";"),start);\r
+\r
+       CString server=TO.Mid(at+1);\r
+\r
+       PDNS_RECORD pDnsRecord; \r
+\r
+       DnsQuery(server, DNS_TYPE_MX,DNS_QUERY_BYPASS_CACHE,\r
+                                           NULL,                   //Contains DNS server IP address.\r
+                        &pDnsRecord,                //Resource record that contains the response.\r
+                        NULL); \r
+\r
+       CString name,address;\r
+       GetNameAddress(this->m_Author,name,address);\r
+\r
+\r
+       CStringArray attchments,CCArray;\r
+       if(bAttachment)\r
+       {\r
+               attchments.Add(pathfile);\r
+       }\r
+       \r
+       ConvertToArray(CC,CCArray);\r
+\r
+       SendEmail(FALSE,pDnsRecord->Data.MX.pNameExchange,\r
+               NULL,NULL,FALSE,address,TO,this->m_Author,TO,this->m_Subject,m_strBody,0,&attchments,&CCArray);\r
+                                       \r
+       DnsRecordListFree(pDnsRecord,DnsFreeRecordList);\r
 \r
+#if 0\r
        CRegString server(REG_SMTP_SERVER);\r
        CRegDWORD  port(REG_SMTP_PORT,25);\r
        CRegDWORD  bAuth(REG_SMTP_ISAUTH);\r
-       CRegDWORD  user(REG_SMTP_USER);\r
-       CRegDWORD  password(REG_SMTP_PASSWORD);\r
+       CRegString  user(REG_SMTP_USER);\r
+       CRegString  password(REG_SMTP_PASSWORD);\r
 \r
        mail.SetSMTPServer(CUnicodeUtils::GetUTF8(server),port);\r
 \r
@@ -61,6 +105,8 @@ int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)
        }\r
 \r
        return !mail.Send();\r
+#endif\r
+\r
 \r
 }\r
 \r
@@ -90,9 +136,13 @@ int CPatch::Parser(CString &pathfile)
 \r
        m_Body.resize(PatchFile.GetLength() - PatchFile.GetPosition());\r
        PatchFile.Read(&m_Body.at(0),PatchFile.GetLength() - PatchFile.GetPosition());\r
+       m_Body.push_back(0);\r
 \r
        PatchFile.Close();\r
 \r
+       g_Git.StringAppend(&m_strBody,&m_Body[0],CP_ACP);\r
+       \r
+\r
 }\r
 \r
 void CPatch::GetNameAddress(CString &in, CString &name,CString &address)\r