test1.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <iostream>
00032 #include <pop3.h>
00033 #include <stdlib.h>
00034
00035 using namespace std;
00036
00037 int main(int argc, char *argv[])
00038 {
00039 POP3 session;
00040
00041 char const *error;
00042
00043 if(argc != 4)
00044 {
00045 cout << "error expected 3 arguments: server user password" << endl;
00046 exit(1);
00047 }
00048
00049 error = session.connect(argv[1], argv[2], argv[3]);
00050
00051 if(error)
00052 {
00053 cout << "Error "
00054 << error
00055 << ", connecting to server, "
00056 << argv[1]
00057 << ", using userid "
00058 << argv[2]
00059 << ", and password "
00060 << argv[3]
00061 << "."
00062 << endl;
00063 exit(1);
00064 }
00065
00066 cout << session.messages()
00067 << " messages were retrieved"
00068 << endl;
00069
00070 size_t i;
00071
00072 for(i = 0; i < session.messages(); ++i)
00073 {
00074 POP3::Header* h;
00075
00076 error = session.message_header(i, &h);
00077
00078 if(error)
00079 cout << "Error retrieving message " << i
00080 << ", " << error << endl;
00081 else
00082 {
00083 cout << "-------------------------------------------------------" << endl;
00084 cout << "-------------------------------------------------------" << endl;
00085
00086 cout << "ID:" << h->id_ << endl;
00087 cout << "DATE:" << h->date_ << endl;
00088 cout << "FROM: ";
00089 {
00090 POP3::userlist_t::iterator first = h->from_.begin(),
00091 last = h->from_.end();
00092
00093 while(first != last)
00094 {
00095 POP3::User &cur = *first++;
00096
00097 cout << cur.email_address_ << " ";
00098 }
00099
00100 cout << endl;
00101 }
00102 cout << "TO: ";
00103 {
00104 POP3::userlist_t::iterator first = h->to_.begin(),
00105 last = h->to_.end();
00106
00107 while(first != last)
00108 {
00109 POP3::User &cur = *first++;
00110
00111 cout << cur.email_address_ << " ";
00112 }
00113
00114 cout << endl;
00115 }
00116 cout << "BCC: ";
00117 {
00118 POP3::userlist_t::iterator first = h->bcc_.begin(),
00119 last = h->bcc_.end();
00120
00121 while(first != last)
00122 {
00123 POP3::User &cur = *first++;
00124
00125 cout << cur.email_address_ << " ";
00126 }
00127
00128 cout << endl;
00129 }
00130 cout << "SUBJECT:" << h->subject_ << endl;
00131
00132 POP3::Body* b;
00133
00134 session.message_body(i,&b);
00135
00136 {
00137 POP3::stringlist_t::iterator first = h->options_.begin(),
00138 last = h->options_.end();
00139
00140 while(first != last)
00141 {
00142 cout << " |" << *first++ << endl;
00143 }
00144
00145
00146 }
00147
00148
00149 POP3::stringlist_t::iterator first = b->lines_.begin(),
00150 last = b->lines_.end();
00151
00152 while(first != last)
00153 {
00154 cout << " >" << *first++ << endl;
00155 }
00156
00157 }
00158
00159 }
00160
00161
00162 return 0;
00163 }