Overview
Features
Download
Documentation
Community
Add-Ons & Services

How to use POP3ClientSession::retrieveMessage ?

A general discussion forum.

How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 03 Nov 2010, 15:43

In ...\poco-1.3.6p2-all\Net\src\POP3ClientSession.cpp :
Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message, PartHandler& handler)

If a message has many different kinds of attachments, only one "PartHandler" is enough ?
I've learnt poco lib for 3 days and sorry for my poor discription :)
Thanks
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 04 Nov 2010, 08:14

I reread the source code, it seems that I should derive my own class from PartHandler and overwrite the handlePart function, and my own handlePart function will do a lot of things, right ? :)
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby guenter » 04 Nov 2010, 23:58

That would be a good start.
guenter
 
Posts: 1092
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 05 Nov 2010, 03:59

guenter wrote:That would be a good start.

Can I leave my messages on server using POCO ? Or maybe I should extend some components of it? If not, imap would be the only choice?
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 05 Nov 2010, 05:50

Why these codes don't work properly ?
Code: Select all
std::vector<POP3ClientSession::MessageInfo> infos;

   session.listMessages(infos);

   if (infos.empty() == false)
   {
      MessageHeader header;
      MailMessage message;
      session.retrieveHeader(infos.size(), header);
      std::string str;
      str = header.get("From");
      str = header.get("To");
      str = header.get("Subject");

      session.retrieveMessage(infos.size(), message);
      str = message.getContent();
   }

   session.close();


Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message)
{
   std::string response;
   sendCommand("RETR", NumberFormatter::format(id), response); // the problem reside here
   if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
   DialogInputStream sis(_socket);
   MailInputStream mis(sis);
   message.read(mis);
   while (mis.good()) mis.get(); // read any remaining junk
}


Is there anything wrong?
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 08 Nov 2010, 05:53

coldiceangel wrote:Why these codes don't work properly ?
Code: Select all
std::vector<POP3ClientSession::MessageInfo> infos;

   session.listMessages(infos);

   if (infos.empty() == false)
   {
      MessageHeader header;
      MailMessage message;
      session.retrieveHeader(infos.size(), header);
      std::string str;
      str = header.get("From");
      str = header.get("To");
      str = header.get("Subject");

      session.retrieveMessage(infos.size(), message);
      str = message.getContent();
   }

   session.close();


Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message)
{
   std::string response;
   sendCommand("RETR", NumberFormatter::format(id), response); // the problem reside here
   if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
   DialogInputStream sis(_socket);
   MailInputStream mis(sis);
   message.read(mis);
   while (mis.good()) mis.get(); // read any remaining junk
}


Is there anything wrong?


It seems that
Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message)
is only used for singl-part message, right ?

I find
Code: Select all
void POP3ClientSession::retrieveHeader(int id, MessageHeader& header)

and
Code: Select all
void MailMessage::readHeader(std::istream& istr)

cannot handle some additional words like these : This is a multi-part message in MIME format.
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 09 Nov 2010, 05:06

When I try to decode reply message of an original email, Base64Decoder cannot work properly and output nothing, why ? Is there anybody who can help me ? Thanks :oops:
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 09 Nov 2010, 05:34

coldiceangel wrote:When I try to decode reply message of an original email, Base64Decoder cannot work properly and output nothing, why ? Is there anybody who can help me ? Thanks :oops:


Problem is solved.
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 09 Nov 2010, 05:40

coldiceangel wrote:
coldiceangel wrote:Why these codes don't work properly ?
Code: Select all
std::vector<POP3ClientSession::MessageInfo> infos;

   session.listMessages(infos);

   if (infos.empty() == false)
   {
      MessageHeader header;
      MailMessage message;
      session.retrieveHeader(infos.size(), header);
      std::string str;
      str = header.get("From");
      str = header.get("To");
      str = header.get("Subject");

      session.retrieveMessage(infos.size(), message);
      str = message.getContent();
   }

   session.close();


Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message)
{
   std::string response;
   sendCommand("RETR", NumberFormatter::format(id), response); // the problem reside here
   if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
   DialogInputStream sis(_socket);
   MailInputStream mis(sis);
   message.read(mis);
   while (mis.good()) mis.get(); // read any remaining junk
}


Is there anything wrong?


It seems that
Code: Select all
void POP3ClientSession::retrieveMessage(int id, MailMessage& message)
is only used for singl-part message, right ?

I find
Code: Select all
void POP3ClientSession::retrieveHeader(int id, MessageHeader& header)

and
Code: Select all
void MailMessage::readHeader(std::istream& istr)

cannot handle some additional words like these : This is a multi-part message in MIME format.


This is my solution:
In
Code: Select all
void POP3ClientSession::retrieveHeader(int id, MessageHeader& header)
,
I add some codes like these:
Code: Select all
int ch = 0;
         // skip stuff following header
    ch = mis.get(); // \r---not sure
    ch = mis.get(); // \n---not sure
          if (ch != '\n')
      mis.putback(ch);

   // ignore:This is a multi-part message in MIME format.
   while(mis.good()) ch = mis.get();
,
is that OK?
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37

Re: How to use POP3ClientSession::retrieveMessage ?

Postby coldiceangel » 09 Nov 2010, 11:00

I am only using text/plain now, and the charset is set to "gb2312", but sometimes the base64-encoded content adds an abitary character at the end, for example:
xOO6w7ChCsTjusO6w7ChLg==
is what I want,
but sometimes the .eml file shows
Code: Select all
xOO6w7ChCsTjusO6w7ChLg==?

or
Code: Select all
xOO6w7ChCsTjusO6w7ChLg==I

or
xOO6w7ChCsTjusO6w7ChLg==O


why?
coldiceangel
 
Posts: 14
Joined: 03 Nov 2010, 13:37


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron