OSDN Git Service

Success Send patch body but attachment have been problem
authorFrank Li <lznuaa@gmail.com>
Fri, 17 Apr 2009 06:29:55 +0000 (14:29 +0800)
committerFrank Li <lznuaa@gmail.com>
Fri, 17 Apr 2009 06:29:55 +0000 (14:29 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/Patch.cpp
src/TortoiseProc/Patch.h
src/Utils/HwSMTP.cpp
src/Utils/HwSMTP.h

index accea84..37776b7 100644 (file)
@@ -5,6 +5,7 @@
 #include "unicodeutils.h"\r
 #include "hwsmtp.h"\r
 #include "Windns.h"\r
+#include "Git.h"\r
 \r
 CPatch::CPatch()\r
 {\r
@@ -17,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
@@ -46,8 +58,16 @@ int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment)
        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,_T("Test"));\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
@@ -119,6 +139,9 @@ int CPatch::Parser(CString &pathfile)
 \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
index 46d2480..8cc6c7a 100644 (file)
@@ -24,4 +24,6 @@ public:
        CString m_Subject;\r
        CString m_PathFile;\r
        std::vector<BYTE> m_Body;\r
+       CString m_strBody;\r
+       void ConvertToArray(CString &to, CStringArray &Array);\r
 };\r
index 84d0b20..fe32da3 100644 (file)
@@ -213,7 +213,24 @@ BOOL CHwSMTP::GetResponse ( LPCTSTR lpszVerifyCode, int *pnCode/*=NULL*/)
 \r
        return TRUE;\r
 }\r
+BOOL CHwSMTP::SendBuffer(char *buff,int size)\r
+{\r
+       if(size<0)\r
+               size=strlen(buff);\r
+       if ( !m_bConnected )\r
+       {\r
+               m_csLastError.Format ( _T("Didn't connect") );\r
+               return FALSE;\r
+       }\r
 \r
+       if ( m_SendSock.Send ( buff, size ) != size )\r
+       {\r
+               m_csLastError.Format ( _T("Socket send data failed") );\r
+               return FALSE;\r
+       }\r
+       \r
+       return TRUE;\r
+}\r
 // ÀûÓÃsocket·¢ËÍÊý¾Ý£¬Êý¾Ý³¤¶È²»Äܳ¬¹ý10M\r
 BOOL CHwSMTP::Send(LPCTSTR lpszData, ... )\r
 {\r
@@ -454,7 +471,11 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName)
                return FALSE;\r
        }\r
 \r
+       if(!Send ( csAttach ))\r
+               return FALSE;\r
+\r
        CFile file;\r
+       CStringA filedata;\r
        try\r
        {\r
                if ( !file.Open ( lpszFileName, CFile::modeRead ) )\r
@@ -464,9 +485,8 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName)
                }\r
                UINT nFileLen = file.Read ( pBuf, dwFileSize );\r
                CBase64 Base64Encode;\r
-               csTemp = Base64Encode.Encode ( pBuf, nFileLen );\r
-               csAttach += csTemp;\r
-               csAttach += _T("\r\n\r\n");\r
+               filedata = Base64Encode.Encode ( pBuf, nFileLen );\r
+               filedata += _T("\r\n\r\n");\r
        }\r
        catch ( CFileException e )\r
        {\r
@@ -476,6 +496,10 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName)
                return FALSE;\r
        }\r
 \r
+       if(!SendBuffer( filedata.GetBuffer() ))\r
+               return FALSE;\r
+\r
+       csAttach.Empty();\r
        csTemp.Format ( _T("--%s\r\n"), m_csPartBoundary );\r
        csAttach += csTemp;\r
 \r
index 5d8454f..79db3a0 100644 (file)
@@ -77,6 +77,7 @@ private:
        BOOL auth();\r
        BOOL SendEmail();\r
        BOOL Send ( LPCTSTR lpszData, ... );\r
+       BOOL SendBuffer(char *buffer,int size=-1);\r
        BOOL GetResponse( LPCTSTR lpszVerifyCode, int *pnCode=NULL );\r
        BOOL m_bConnected;\r
        CSocket m_SendSock;\r