Code:
/////////////////////////////////////////////////////////////////////////////
/// File Upload (one file only)
///
/// \param inURL VCL
/// \param inFileName description
/// \param inAuthToken description
/// \param outFileToken description
/// \param outRequestId description
///
/// \return
///
/// \author HMB
/// \date
/////////////////////////////////////////////////////////////////////////////
bool __fastcall TfrmEMail::SubmitFile(String inFileName,String& outFileToken,String& outRequestId)
{
TStringList *l_response = NULL;
String l_hlp;
bool r_Ok = false;
__try
{
try
{
int l_Idx=0;
if (!IsZimbraLogedOn())
throw Exception("Error:Try to Submit File but not logged in at:" + m_EMailServerHostName);
l_response = new TStringList();
htpReqMail->Clear();
htpReqMail->Header->Clear();
htpReqMail->Header->Host = m_EMailServerHostName;
htpReqMail->AddFormField("FileName",inFileName);
htpReqMail->AddFormField("requestId", IntToHex(random(MaxInt),8));
htpReqMail->AddSubmitFile(inFileName,"FileName");
htpReqMail->Header->ExtraFields->Add("Cookie: ZM_AUTH_TOKEN=" + m_AuthKey);
htpSoap->Post(m_UrlUpload,htpReqMail,l_response);
if (l_response->Text.SubString(1,3) == "200")
{
l_Idx = l_response->Text.Pos(",'");
l_hlp = l_response->Text.SubString(l_Idx+1,l_response->Text.Length() - l_Idx);
l_Idx = l_hlp.Pos("','") +1 ;
outRequestId = l_hlp.SubString(2,l_Idx-3);
outFileToken = l_hlp.SubString(l_Idx+2,l_hlp.Length()-(l_Idx+4));
}
else
throw Exception("Error during upload:" + inFileName + " in SubmitFile-function:\r\n" +l_response->Text);
r_Ok = true;
}
catch(Exception &ex)
{
MessageDlg(ex.Message, mtError, TMsgDlgButtons() << mbOK, 0);
}
}
__finally
{
if (l_response)
delete l_response;
}
return r_Ok;
}
/////////////////////////////////////////////////////////////////////////////
/// Login bei Zimbra
///
/// \param Sender VCL
/// \param paramname2 description
///
/// \return description....
///
/// \author HMB
/// \date
/////////////////////////////////////////////////////////////////////////////
bool __fastcall TfrmEMail::ZimbraLogin(String inName,String inPassword)
{
bool r_Ok = false;
TStringList *l_strXml=NULL,
*l_response = NULL;
__try
{
try
{
l_response = new TStringList();
l_strXml = new TStringList();
BuildZMAuthRequest(inName,inPassword,l_strXml);
htpReqMail->Clear();
htpReqMail->Header->Host = m_EMailServerHostName;
htpReqMail->Header->Accept = "text/xml,*.*";
htpReqMail->AddTextData(l_strXml->Text);
//
htpSoap->Post(m_UrlSoap,htpReqMail,l_response);
//
// SessionId (wird z.Zt. nicht gebraucht)
if (!GetXmlItem("sessionId","",l_response->Text,m_SessionId))
throw Exception("Item/Token not found :sessionId");
//authToken
if (!GetXmlItem("authToken","",l_response->Text,m_AuthKey))
throw Exception("Item/Token not found :authToken" );
// change token
if (!GetXmlItem("change","token",l_response->Text,m_ChangeToken))
throw Exception("Item/Token not found :ChangeToken" );
r_Ok = true;
}
catch(Exception &ex)
{
// throw EAPError(ex.Message,0,"tagProblem...","[Modul.cpp]","Text", "Procedure",0);
MessageDlg(ex.Message +"\r\nSOAP:"+ m_UrlSoap +"\r\nHOST:"+ htpReqMail->Header->Host, mtError, TMsgDlgButtons() << mbOK, 0);
}
}
__finally // Aufräumen
{
if (l_response)
delete l_response;
if (l_strXml)
delete l_strXml;
}
return r_Ok;
} as you can see, this all is linked to many other methodes, which is too huge to show all here. But finally it sends mails with files attached.