00001 #include "oc_IMap.h"
00002
00003
00004 void mailCli( oc_IMap & mail )
00005 {
00006 char sendline[MAXLINE];
00007
00008 cout << "mail>>";
00009 while (fgets(sendline, MAXLINE, stdin) != NULL)
00010 {
00011 if( strlen( sendline )> 1 )
00012 {
00013
00014 cout << endl << "Command: " << sendline ;
00015 mail.Command( sendline );
00016 do
00017 {
00018
00019 string Response = mail.Response();
00020 if( Response.length() )
00021 {
00022 cout << Response;
00023 }
00024 } while ( ! mail.GetResponseComplete() );
00025
00026 cout << "==============end of read============" << endl;
00027
00028 }
00029 cout << "mail>>";
00030 }
00031 }
00032
00033 int main(int argc, char *argv[])
00034 {
00035 if( argc == 4 )
00036 {
00037 try
00038 {
00039 oc_IMap mail( "webMail", "127.0.0.1", 143 );
00040
00041
00042 if( mail.login( argv[1], argv[2] ) )
00043 {
00044 cout << "login ok" << endl;
00045
00046 if( mail.select( argv[3] ) )
00047 {
00048 cout << "mailbox ok" << endl;
00049 if( mail.fetchHeaders() )
00050 {
00051 cout << "==== Items in mail =====" << endl;
00052 vector <string> & listItems = mail.GetListItems();
00053 for( size_t x=0; x<listItems.size(); x++ )
00054 {
00055 mlistItem mitem( listItems[x] );
00056 cout << "id " << mitem.id << endl
00057 << " to " << mitem.to << endl
00058 << " from " << mitem.from << endl
00059 << " sent " << mitem.sent << endl
00060 << " reply_to " << mitem.reply_to << endl
00061 << " cc " << mitem.cc << endl
00062 << " subject " << mitem.subject << endl
00063 << " received " << mitem.received << endl
00064 << " flags " << mitem.flags << endl
00065 << " size " << mitem.size << endl
00066 << endl;
00067 }
00068 cout << "==== End of items in mail =====" << endl;
00069 }
00070
00071
00072 cout << mail.fetchRFC822("1");
00073
00074
00075 mailCli( mail );
00076 }
00077 else throw exception();
00078 }
00079 else throw exception();
00080
00081 }
00082 catch( exception & err )
00083 {
00084 cout << "Caught " << err.what() << endl;
00085 return -1;
00086 }
00087 }
00088 else
00089 {
00090 cout << "usage: oc_IMap user pwd mailbox" << endl;
00091 }
00092 return 0;
00093 }
00094
00095
00096