Board index » cppbuilder » Decoding email subject string (or generally an email message)

Decoding email subject string (or generally an email message)


2005-05-05 11:26:38 PM
cppbuilder18
Normally when I receive mail in koi8-r encoding I see subject lines the way
they were originally typed by sender, normal cyrillic symbols.
I use NetMasters' NMPOP3 component to get subject of an email message and
get this line :
" =?koi8-r?B?1MXCxSk=?="
...instead of normal russian text. Sure, my program doesn't know how to
decode this. The question is...
how do I programmatically decode that string? obviously first few symbols
tell me the encoding.... but what should I do next?
 
 

Re:Decoding email subject string (or generally an email message)

"Danila Vershinin" < XXXX@XXXXX.COM >wrote in message
Quote
how do I programmatically decode that string? obviously first
few symbols tell me the encoding.... but what should I do next?
Read RFC 2047 (www.ietf.org/rfc/rfc2047.txt). It explains how to
decode that data.
With that said, I would suggest dumping Netmasters altogether. It is a
notoriously buggy library that has been very problematic over the years.
Switch to a different library, such as Indy (www.indyproject.org) or
ICS (www.overbyte.be). As for decoding, I don't think ICS supports
decoding those header encodings, but Indy does.
Gambit
 

Re:Decoding email subject string (or generally an email message)

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
Switch to a different library, such as Indy (www.indyproject.org)
or ICS (www.overbyte.be).
Ok, interesting that you've mentioned about Indy now....
...now that I've spent the whole day making TidPOP3 component work the way
it should.
the problem appeared all the time when I tried to do things like:
MailCount = Mail->CheckMessages(); // Mail is TIdPOP3 component and
MailCount is : int MailCount defined in private section of form class....
just checking number or messages on the server....
And what do I get from this simple task?, what you think?
An exception of class EConvertError with message "'Teapop' is not a valid
integer value" Teapop? huh?)
nothing written in the documentation about Teapop constant or whatever...
so in my sincere desperation I've switched to NetMasters, buggy, but seeming
more bugless than Indy... the only bad thing about it is that issue with
decoding.... by the way, thanks for the link
 

{smallsort}

Re:Decoding email subject string (or generally an email message)

"Danila Vershinin" < XXXX@XXXXX.COM >wrote in message
Quote
the problem appeared all the time when I tried to do things like:
MailCount = Mail->CheckMessages(); // Mail is TIdPOP3 component
and MailCount is : int MailCount defined in private section of form
class....
just checking number or messages on the server....
And what do I get from this simple task?, what you think?
An exception of class EConvertError with message "'Teapop' is not a valid
integer value" Teapop? huh?)
Then your server is likely not sending a valid response back to begin with.
TIdPOP3 has been around for a long time, it is a mature component that a lot
of people use it without problem. Please show your actual code, and the
actual commands/responses that are being passed over the socket. You can
use a packet sniffer, such as Ethereal (www.ethereal.com), or attach
one of the TIdLog... components to TIdPOP3's Intercept property, to get that
communication data.
Quote
nothing written in the documentation about Teapop constant or whatever...
The value would be coming from the POP3 server itself, not Indy.
Gambit
 

Re:Decoding email subject string (or generally an email message)

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
Please show your actual code, and the actual commands/responses that are
being passed over the socket
Unit1.h
//--------------------------------------------------------------------------------------------------------
...
private: // User declarations
int MailCount;
...
//--------------------------------------------------------------------------------------------------------
Unit1.cpp
//-------------------------------------------------------------------------------------------------------
...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Log->Active = true;
Mail->Connect();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MailConnected(TObject *Sender)
{
MailCount = Mail->CheckMessages();
}
//---------------------------------------------------------------------------
TIdLog gave this:
email.log
//--------------------------------------------------------------------------
5/6/2005 12:40:40 AM: Connected.
5/6/2005 12:40:40 AM: Sent: STAT<EOL>
5/6/2005 12:40:41 AM: Recv: +OK Teapop [v0.3.4] - Teaspoon stirs around
again <1115325644.74676B00@Llywellyn><EOL>
//--------------------------------------------------------------------------
Yeah, server responds in inappropriate way I guess)) and yes, it's not
Indy's fault, but it could work... like NetMasters do now, with the same
account ...but Indy doesn't work, it calls the exception (
 

Re:Decoding email subject string (or generally an email message)

"Danila Vershinin" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TForm1::MailConnected(TObject *Sender)
{
MailCount = Mail->CheckMessages();
}
The error you are seeing is caused by a bug in your own code, not Indy's.
You cannot call CheckMessage() from the OnConnected event handler. This is
because TIdPOP3 overrides the TIdTCPClient::Connect() method to perform
additional operations needed to log into the POP3 server. The first thing
TIdPOP3::Connect() does is to call TIdTCPClient::Connect() to establish the
actual socket connection. After TIdTCPClient::Connect() returns,
TIdPOP3::Connect() then reads the server's Greeting and sends the
username/password. Because the OnConnected event is triggered by
TIdTCPClient::Connect(), not TIdPOP3::Connect(), you are calling
CheckMessages() before TIdPOP3 has a chance to read the Greeting or login.
As such, when CheckMessages() attempts to get the server's reply to the STAT
command, it is reading the server's Greeting instead. That is why you get
the parsing error.
To fix the problem, you must not call CheckMessages() until after
TIdPOP3::Connect() returns. That means moving your call to CheckMessages()
into your button OnClick handler instead, ie:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Mail->Connect();
Mail->CheckMessages(); // <-- wait until Connect() returns first
//...
}
Gambit
 

Re:Decoding email subject string (or generally an email message)

Thanks)
 

Re:Decoding email subject string (or generally an email message)

After i've figured out that indy is better I decided to download a new one
=) the 10th version... in the attachments NG I found the BCB packages for
it...
ok... compiling System and Core went fine... but when it came to compiling
Protocols there were error like :"undeclared identifer 'TIdIPVersion".. I
don't remember exactly.... so I thought that could be include issue or
whatever...
I just put all the files from System, Core and Protocols into one directory,
and then protocols compiled fine.......
but only one thing, when I put Indy POP3 component on the form I have so man
mistakes... in some Indy headers... what did I do wrong.. obviously it was
wrong to put the files into one folder...
but the questions is, where do I find installation instructions for BCB?
yeah, I saw them on the site but that came to be not enough. When I used
that info, I failed to install protocols... there is the automatic
installer, but I think it is for Delphi only....
 

Re:Decoding email subject string (or generally an email message)

"Danila Vershinin" < XXXX@XXXXX.COM >wrote in message
Quote
when I put Indy POP3 component on the form I have so
man mistakes... in some Indy headers...
Please be more specific.
Gambit