Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-2008, 08:55 AM
Member
 
Posts: 10
Default Transmit Cookie??

Hello,
i would like to prepare a cookie for a TIdHTTP based communication to a Zimbra server.
I use Codegear Builder (RadStuio 2007) and Indy-Components (Ver 10.1.5). The host name is 'zimbra'

So I set 2 components on my form: TIdHTTP and TIdCookieManager and connected them. Also AllowsCookie is set to true.
To get the authentication i send a request via soap to the zimbra and received this long Hex-String which is saved inside m_AuthKey.

I created the cookie by the following line:

Code:
	String l_Cookie = "ZM_AUTH_KEY=" + m_AuthKey+ ";Name=ZM_AUTH_KEY";
	IdCookieManager->AddCookie(l_Cookie,"zimbra");
	ShowCookies( IdCookieManager->CookieCollection);
ShowCookies does not deliver any Error:
Code:
void __fastcall TfrmTestSoap::ShowCookies( TIdCookies *inCC)
{
	for (int i = 0; i < inCC->Count; i++)
	{
		TIdCookieRFC2109 *l_c = inCC->Items[i];
		memLog->Lines->Add("CName(" + IntToStr(i)+ ")=" + l_c->CookieName);
		memLog->Lines->Add("CText(" + IntToStr(i)+ ")=" + l_c->CookieText);
		memLog->Lines->Add("CValue(" + IntToStr(i)+ ")=" + l_c->Value);
		memLog->Lines->Add("CComment(" + IntToStr(i)+ ")=" + l_c->Comment);
		if (!l_c->IsValidCookie("zimbra"))
			MessageDlg("Cookie???", mtError, TMsgDlgButtons() << mbOK, 0);
	}
}
it delivers:

CName(0)=ZM_AUTH_KEY
CText(0)=ZM_AUTH_KEY=0_e1b690c2c8e0be937ff6f4404d8 23857a964a164_69643d33363a34366163363835342d383865 622d346331642d613731632d3839303333393630653830393b 6578703d31333a313232353132323937303238303b74797065 3d363a7a696d6272613b; path=/; domain=zimbra
CValue(0)=0_e1b690c2c8e0be937ff6f4404d823857a964a1 64_69643d33363a34366163363835342d383865622d3463316 42d613731632d3839303333393630653830393b6578703d313 33a313232353132323937303238303b747970653d363a7a696 d6272613b

So Cookie seems to be valid
After that I try to send a sample mail via Http/Mime:
Code:
void __fastcall TfrmTestSoap::btnBuildMimeClick(TObject *Sender)
{
	String l_msg,l_url="http://zimbra/service/upload";
	TIdEMailAddressItem *l_adrItem;
	TMemoryStream *l_mem = NULL;

	try
	{
       try
	   {
		l_mem = new TMemoryStream();

		IdMessage1->Clear();
		IdMessage1->From->Address = "[e-mailaddress]";
		IdMessage1->Subject =  "Mime-Test";
		IdMessage1->Body->Add("Das ist ein body-Test");
		l_adrItem = IdMessage1->Recipients->Add();
		l_adrItem->Address = "[receipient@somewhere.de";
		new TIdAttachmentFile(IdMessage1->MessageParts, "C:\\Zip\\ReadMe.txt");
	
		IdMessage1->SaveToFile("D:\\MyMail.txt",false);
		IdMessage1->SaveToStream(l_mem,false);

		htpMain->Request->ContentType ="message/rfc822";
		memLog->Lines->Add("CookkieLine=" +
		IdCookieManager->GenerateCookieList(htpMain->URL));
		l_msg =	htpMain->Post(l_url,l_mem);

		MessageDlg("Msg:" + l_msg, mtWarning, TMsgDlgButtons() << mbOK, 0);


	   }
       catch(Exception &ex)
       {
         MessageDlg(ex.Message, mtError, TMsgDlgButtons() << mbOK, 0);
       }
    }
    __finally
    {
	  if (l_mem)
		  delete l_mem;
	}

}


Where
Code:
 memLog->Lines->Add("CookkieLine=" +
		IdCookieManager->GenerateCookieList(htpMain->URL));
delivers:
CookkieLine=ZM_AUTH_KEY=0_7a70d6a8fcaa1652725cc41f 08774e7c2252a01f_69643d33363a34366163363835342d383 865622d346331642d613731632d38393033333936306538303 93b6578703d31333a313232353132313238333638303b74797 0653d363a7a696d6272613b

and
Code:
l_msg =	htpMain->Post(l_url,l_mem);
delivers the error : HTTP1.1 no authoken cookie

So here is the question:
How can I check why zimbra is unable to take my Cookie while Post(ing) the Message?
Any idea??
The target is to send mails with uploaded attachments.

Last edited by hmb2000; 10-25-2008 at 08:58 AM..
Reply With Quote
  #2 (permalink)  
Old 10-27-2008, 03:40 AM
Member
 
Posts: 10
Default Cookie Name ?

I have reread file-upluad.txt and found that the cookies name differs:

A request at the http level looks something like this:


POST /service/upload HTTP/1.1
Cookie: LS_AUTH_TOKEN=0_6029...
Content-Type: multipart/form-data; boundary=SKhAvar1nat0rt3mp
Host: localhos ...

so I renamed the token/Cookie and monitored it with WireShark:
===============================================
POST /service/upload?fmt=raw HTTP/1.0
Connection: keep-alive
Content-Type: multipart/form-data
Content-Length: 7919
Host: zimbra
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)
Cookie: LS_AUTH_TOKEN=0_621319971291f41f8ba290873f79f2be1c 61851d_69643d33363a34366163363835342d383865622d346 331642d613731632d3839303333393630653830393b6578703 d31333a313232353237363034313638343b747970653d363a7 a696d6272613b
...
MIME-Version: 1.0
Date: Mon, 27 Oct 2008 11:27:21 +0000
Content-Type: application/octet-stream;
name="ReadMe.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="ReadMe.txt"

DQogICAgICAgICAgICAgICBXZWxjb21lIHRvIHRoZSBEZWxaaX AgdjEuNiBSZWxlYXNlIQ0KICAg
ICAgICAgICAgIFRoaXMgaXMgdGhlIEJvcmxhbmQgQysrIEJ1aW xkZXIgRWRpdGlvbg0KICAgICAg
ICAgICAgICAgICAgICAgICAgICBGZWIuIDMsIDIwMDANCg0KDQ pUaGlzIGlzIGEgYmV0YSByZWxl
YXNlIG9mIERlbFppcCB2ZXJzaW9uIDEuNiBUaGlzIHJlbGVhc2 UNCmlzIGNvbXByZWhlbnNpdmUg
LSBpdCBpbmNsdWRlcyBhbGwgdGhlIGZpbGVzIHlvdSBuZWVkLi BUaGlzIHNob3VsZCANCndvcmsg
b24gQm9ybGFuZCBDKysgQnVpbGRlciwgdmVyc2lvbnMgMSwgMy BhbmQgNC4NClRoZSBEZWxwaGkg
cmVsZWFzZSBpcyBub3cgZGlzdHJpYnV0ZWQgc2VwYXJhdGVseS 4NCg0KDQpUaGlzIHJlbGVhc2Ug
Y29udGFpbnM6DQoNCkRaLUJDQjE2MC5FWEUgIC0gb3ZlcmFsbC BGcmVld2FyZSBEZWxaaXAgdjEu
NiBwYWNrYWdlLg0KDQpUaGUgbWFpbiBzZXR1cCBkaXJlY3Rvcn kgZGVmYXVsdHMgdG8gQzpcWmlw
QmV0YS4NClRoZSByZXN0IG9mIHRoaXMgZG9jdW1lbnQgYXNzdW 1lcyB5b3Ugc2VsZWN0ZWQgdGhh
dA0KZGlyZWN0b3J5IGZvciB0aGUgaW5zdGFsbC4NCg0KRmlsZX MgaW4gTWFpbiBkaXJlY3Rvcnk6
DQoNCiAgXFppcEJldGFcUkVBRE1FLlRYVCAgICAtIHRoaXMgZm lsZQ0KDQogIFxaaXBCZXRhXElO
U1QtQkNCMS5UWFQgLSBpbmZvLiBhYm91dCBob3cgdG8gaW5zdG FsbCB0aGUgVkNMcyBhbmQNCiAg
ICAgICAgICAgICAgICAgICAgICAgICAgIHJ1biB0aGUgZGVtby BpbiBCQ0IgdmVyc2lvbiAxDQoN
CiAgXFppcEJldGFcSU5TVC1CQ0IzLlRYVCAtIGluZm8uIGFib3 V0IGhvdyB0byBpbnN0YWxsIHRo
ZSBWQ0xzIGFuZA0KICAgICAgICAgICAgICAgICAgICAgICAgIC AgcnVuIHRoZS
....

ERROR IS STILL:

HTML Code:
HTTP/1.1 401 no authtoken cookie
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 401 </title>
</head>
<body><h2>HTTP ERROR: 401</h2><pre>no authtoken cookie</pre>
<p>RequestURI=/service/upload</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                

</body>
</html>
Reply With Quote
  #3 (permalink)  
Old 10-27-2008, 11:52 AM
Member
 
Posts: 10
Default Solved, but next Problem

Now zimbra is accepting the cookie
http://zimbra/service/upload?fmt=extended
or
http://zimbra/service/upload?fmt=raw
and
ZM_AUTH_TOKEN
is the right name for the cookie.
But now the answer is

HTML Code:
<html><head><script language='javascript'>
function doit() { window.parent._uploadManager.loaded(204,'null'); }
</script></head><body onload='doit()'></body></html>
this (204 ) ist still wrong,
with wireshark I monitored:


POST /service/upload?fmt=extended HTTP/1.0
Connection: keep-alive
Content-Type: multipart/form-data; boundary=
Content-Length: 1078
Host: zimbra
Accept: text/html, */*
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: identity
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)
Cookie: ZM_AUTH_TOKEN=0_bb57ec9f84bc33354fb74ea84294c8aa3a 095f2d_69643d33363a34366163363835342d383865622d346 331642d613731632d3839303333393630653830393b6578703 d31333a313232353330353733303838323b747970653d363a7 a696d6272613b
Content-Type: plain/text;; boundary="29Glr=_yRLQm8uFNPQoRUgMglWkeR95OZz"
MIME-Version: 1.0
Date: Mon, 27 Oct 2008 19:42:15 +0000

?

--29Glr=_yRLQm8uFNPQoRUgMglWkeR95OZz
Content-Type: application/octet-stream;
name="netzwerk.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="netzwerk.txt"

DQ0KV2luZG93cy1JUC1Lb25maWd1cmF0aW9uDQ0KDQ0KDQ0KRX RoZXJuZXRhZGFwdGVyIExBTi1W
ZXJiaW5kdW5nIDI6DQ0KDQ0KICAgICAgICBNZWRpZW5zdGF0dX MuIC4gLiAuIC4gLiAuIC4gLiAu
IC4gOiBFcyBiZXN0ZWh0IGtlaW5lIFZlcmJpbmR1bmcNDQoNDQ pFdGhlcm5ldGFkYXB0ZXIgRHJh
aHRsb3NlIE5ldHp3ZXJrdmVyYmluZHVuZzoNDQoNDQogICAgIC AgIFZlcmJpbmR1bmdzc3Blemlm
aXNjaGVzIEROUy1TdWZmaXg6IA0NCiAgICAgICAgSVAtQWRyZX NzZS4gLiAuIC4gLiAuIC4gLiAu
IC4gLiAuIDogMTAuMC4zLjYNDQogICAgICAgIFN1Ym5ldHptYX NrZS4gLiAuIC4gLiAuIC4gLiAu
IC4gLiA6IDI1NS4yNTUuMC4wDQ0KICAgICAgICBTdGFuZGFyZG dhdGV3YXkgLiAuIC4gLiAuIC4g
LiAuIC4gOiAxMC4wLjAuMjU0DQ0K

--29Glr=_yRLQm8uFNPQoRUgMglWkeR95OZz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

?

--29Glr=_yRLQm8uFNPQoRUgMglWkeR95OZz--

.

Any hints??? p l e a s e!
(The target is still to send mails with uploaded attachments from a ms-window application)
Reply With Quote
  #4 (permalink)  
Old 03-10-2009, 11:46 AM
Junior Member
 
Posts: 8
Exclamation

Hi hmb2000,
Did you have solutions for this?
I got this problem:

<html><head><script language='javascript'>
function doit() { window.parent._uploadManager.loaded(204,'0_6061e38 772812ea5722d1ce46e90e14ac5b6e312_69643d33363a3933 3466393934372d626566352d343832622d396464392d623030 6639616664636330653b6578703d31333a3132333637363335 38373932353b747970653d363a7a696d6272613b'); }
</script></head><body onload='doit()'></body></html>

Please give me advices.
Thanks,
Globus
Reply With Quote
  #5 (permalink)  
Old 03-11-2009, 04:03 AM
Member
 
Posts: 10
Default

Hi
i did not solved it by using Indy, i searched the internet and found and bought the CleverComponent Suite. There seemed to a incompatiblity-issue in the Indy anyway.
At CleverComponents i used TclHttp and TclHttpRequest component. Then finally it worked.
Here is a fragment where htpSoap is the TclHttp-object :
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.