ultimatepp/reference/Pop3/Pop3.cpp
cxl becef7dfc0 reference: Pop3
git-svn-id: svn://ultimatepp.org/upp/trunk@7092 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2014-03-25 09:04:50 +00:00

59 lines
1.7 KiB
C++

#include <Core/POP3/POP3.h>
using namespace Upp;
// WIN32: This example requires OpenSSL .dlls to be available
CONSOLE_APP_MAIN
{
Cout() << "Your GMail username: ";
String user = ReadStdIn();
Cout() << "Your GMail password: ";
String pass = ReadStdIn();
Pop3 pop3;
pop3.Host("pop.gmail.com")
.Port(995)
.User(user, pass)
.SSL()
.Trace(); // Activate logging of Pop3.
Cout() << "Connecting to GMail POP3 server... ";
if(!pop3.Login()) {
Cout() << "Failed: " << pop3.GetLastError() << "\n";
return;
}
int msgcount = pop3.GetMessageCount();
if(msgcount < 0) {
Cout() << "\nFailed: " << pop3.GetLastError() << "\n";
pop3.Logout();
return;
}
Cout() << "There are " << msgcount << " messages in your inbox.\n";
for(;;) {
Cout() << "Message number to retrieve (1.." << msgcount << ") or anything else to QUIT:";
int i = StrInt(ReadStdIn());
if(i >= 1 && i <= msgcount) {
String message = pop3.GetMessage(i);
if(IsNull(message))
Cout() << "An error encountered: " << pop3.GetLastError() << "\n";
else {
InetMessage m;
if(m.Read(message)) {
Cout() << "Subject: " << m["subject"] << "\n"
<< "From: " << m["from"] << "\n"
<< "Date: " << m["date"] << "\n";
for(int i = 0; i < m.GetPartCount(); i++)
Cout() << "========= Part " << i << ", type "
<< Nvl(m.GetPartHeader(i, "content-type"), m["content-type"]) << "\n"
<< m.GetPartBody(i);
Cout() << "-------------------------------------\n";
}
else
Cout() << "Error parsing the message\n";
}
}
else
break;
}
Cout() << "Logging out!..\n";
pop3.Logout();
}