test1.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright 2002, Lowell Boggs Jr.
00004 //
00005 // This file or directory, containing source code for a computer program,
00006 // is Copyrighted by Lowell Boggs, Jr.  987 Regency Drive, Lewisville
00007 // TX (USA), 75067.  You may use, copy, modify, and distribute this
00008 // source file without charge or obligation so long as you agree to
00009 // the following:
00010 //
00011 //  1.  You must indemnify Lowell Boggs against any and all financial
00012 //      obligations caused by its use, misuse, function, or malfunction.
00013 //      Further, you acknowledge that there is no warranty of any kind,
00014 //      whatsoever.
00015 //
00016 //  2.  You agree not to attempt to patent any portion of this original
00017 //      work -- though you may attempt to patent your own extensions to
00018 //      it if you so choose.
00019 //
00020 //  3.  You keep this copyright notice with the file and all copies
00021 //      of the file and do not change it anyway except language translation.
00022 //
00023 // You are responsible for enforcing your own compliance with these
00024 // conditions and may not use this source file if you cannot agree to the
00025 // above terms and conditions.
00026 //
00027 // Warning:  not all files in this directory structure are covered by the
00028 // same copyright.  Some of them are part of the GNU source distribution
00029 // and you must obey the GPL copyright for those files.
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 }
Generated on Wed Feb 29 22:50:05 2012 for CXXUtilities by  doxygen 1.6.3