From df1c4fcb13177a1f683402bc1dfa68e436c72929 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Fri, 17 Apr 2009 14:29:55 +0800 Subject: [PATCH] Success Send patch body but attachment have been problem Signed-off-by: Frank Li --- src/TortoiseProc/Patch.cpp | 25 ++++++++++++++++++++++++- src/TortoiseProc/Patch.h | 2 ++ src/Utils/HwSMTP.cpp | 30 +++++++++++++++++++++++++++--- src/Utils/HwSMTP.h | 1 + 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/TortoiseProc/Patch.cpp b/src/TortoiseProc/Patch.cpp index accea8419..37776b7a9 100644 --- a/src/TortoiseProc/Patch.cpp +++ b/src/TortoiseProc/Patch.cpp @@ -5,6 +5,7 @@ #include "unicodeutils.h" #include "hwsmtp.h" #include "Windns.h" +#include "Git.h" CPatch::CPatch() { @@ -17,6 +18,17 @@ CPatch::~CPatch() } +void CPatch::ConvertToArray(CString &to,CStringArray &Array) +{ + int start=0; + while(start>=0) + { + CString str=to.Tokenize(_T(";"),start); + if(!str.IsEmpty()) + Array.Add(str); + } +} + int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment) { CSmtp mail; @@ -46,8 +58,16 @@ int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment) GetNameAddress(this->m_Author,name,address); + CStringArray attchments,CCArray; + if(bAttachment) + { + attchments.Add(pathfile); + } + + ConvertToArray(CC,CCArray); + SendEmail(FALSE,pDnsRecord->Data.MX.pNameExchange, - NULL,NULL,FALSE,address,TO,this->m_Author,TO,this->m_Subject,_T("Test")); + NULL,NULL,FALSE,address,TO,this->m_Author,TO,this->m_Subject,m_strBody,0,&attchments,&CCArray); DnsRecordListFree(pDnsRecord,DnsFreeRecordList); @@ -119,6 +139,9 @@ int CPatch::Parser(CString &pathfile) PatchFile.Close(); + g_Git.StringAppend(&m_strBody,&m_Body[0],CP_ACP); + + } void CPatch::GetNameAddress(CString &in, CString &name,CString &address) diff --git a/src/TortoiseProc/Patch.h b/src/TortoiseProc/Patch.h index 46d2480ca..8cc6c7a4b 100644 --- a/src/TortoiseProc/Patch.h +++ b/src/TortoiseProc/Patch.h @@ -24,4 +24,6 @@ public: CString m_Subject; CString m_PathFile; std::vector m_Body; + CString m_strBody; + void ConvertToArray(CString &to, CStringArray &Array); }; diff --git a/src/Utils/HwSMTP.cpp b/src/Utils/HwSMTP.cpp index 84d0b20d7..fe32da34c 100644 --- a/src/Utils/HwSMTP.cpp +++ b/src/Utils/HwSMTP.cpp @@ -213,7 +213,24 @@ BOOL CHwSMTP::GetResponse ( LPCTSTR lpszVerifyCode, int *pnCode/*=NULL*/) return TRUE; } +BOOL CHwSMTP::SendBuffer(char *buff,int size) +{ + if(size<0) + size=strlen(buff); + if ( !m_bConnected ) + { + m_csLastError.Format ( _T("Didn't connect") ); + return FALSE; + } + if ( m_SendSock.Send ( buff, size ) != size ) + { + m_csLastError.Format ( _T("Socket send data failed") ); + return FALSE; + } + + return TRUE; +} // ÀûÓÃsocket·¢ËÍÊý¾Ý£¬Êý¾Ý³¤¶È²»Äܳ¬¹ý10M BOOL CHwSMTP::Send(LPCTSTR lpszData, ... ) { @@ -454,7 +471,11 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName) return FALSE; } + if(!Send ( csAttach )) + return FALSE; + CFile file; + CStringA filedata; try { if ( !file.Open ( lpszFileName, CFile::modeRead ) ) @@ -464,9 +485,8 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName) } UINT nFileLen = file.Read ( pBuf, dwFileSize ); CBase64 Base64Encode; - csTemp = Base64Encode.Encode ( pBuf, nFileLen ); - csAttach += csTemp; - csAttach += _T("\r\n\r\n"); + filedata = Base64Encode.Encode ( pBuf, nFileLen ); + filedata += _T("\r\n\r\n"); } catch ( CFileException e ) { @@ -476,6 +496,10 @@ BOOL CHwSMTP::SendOnAttach(LPCTSTR lpszFileName) return FALSE; } + if(!SendBuffer( filedata.GetBuffer() )) + return FALSE; + + csAttach.Empty(); csTemp.Format ( _T("--%s\r\n"), m_csPartBoundary ); csAttach += csTemp; diff --git a/src/Utils/HwSMTP.h b/src/Utils/HwSMTP.h index 5d8454f7b..79db3a0a3 100644 --- a/src/Utils/HwSMTP.h +++ b/src/Utils/HwSMTP.h @@ -77,6 +77,7 @@ private: BOOL auth(); BOOL SendEmail(); BOOL Send ( LPCTSTR lpszData, ... ); + BOOL SendBuffer(char *buffer,int size=-1); BOOL GetResponse( LPCTSTR lpszVerifyCode, int *pnCode=NULL ); BOOL m_bConnected; CSocket m_SendSock; -- 2.11.4.GIT