Demo program for the [[http://mbed.org/users/hlipka/libraries/pop3|pop3 library]].
Dependencies: mbed TcpLineStream NetServicesMin pop3 DNSResolver
main.cpp@0:4a32b2fce260, 2012-04-11 (annotated)
- Committer:
- hlipka
- Date:
- Wed Apr 11 20:35:59 2012 +0000
- Revision:
- 0:4a32b2fce260
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:4a32b2fce260 | 1 | #include "EthernetNetIf.h" |
hlipka | 0:4a32b2fce260 | 2 | |
hlipka | 0:4a32b2fce260 | 3 | #include "mbed.h" |
hlipka | 0:4a32b2fce260 | 4 | |
hlipka | 0:4a32b2fce260 | 5 | #include "pop3.h" |
hlipka | 0:4a32b2fce260 | 6 | |
hlipka | 0:4a32b2fce260 | 7 | main() |
hlipka | 0:4a32b2fce260 | 8 | { |
hlipka | 0:4a32b2fce260 | 9 | EthernetNetIf eth; |
hlipka | 0:4a32b2fce260 | 10 | EthernetErr ethErr; |
hlipka | 0:4a32b2fce260 | 11 | printf("Setting up...\n"); |
hlipka | 0:4a32b2fce260 | 12 | do { |
hlipka | 0:4a32b2fce260 | 13 | ethErr = eth.setup(); |
hlipka | 0:4a32b2fce260 | 14 | if (ethErr) printf("waiting for network...\n", ethErr); |
hlipka | 0:4a32b2fce260 | 15 | } while (ethErr != ETH_OK); |
hlipka | 0:4a32b2fce260 | 16 | |
hlipka | 0:4a32b2fce260 | 17 | Pop3 *p3=new Pop3("mail.server","mail.user","mail.password"); |
hlipka | 0:4a32b2fce260 | 18 | |
hlipka | 0:4a32b2fce260 | 19 | bool r=p3->init(); |
hlipka | 0:4a32b2fce260 | 20 | |
hlipka | 0:4a32b2fce260 | 21 | printf("init ok=%i\n",r); |
hlipka | 0:4a32b2fce260 | 22 | |
hlipka | 0:4a32b2fce260 | 23 | if(r) |
hlipka | 0:4a32b2fce260 | 24 | { |
hlipka | 0:4a32b2fce260 | 25 | list<string> *ids=p3->getMessages(); |
hlipka | 0:4a32b2fce260 | 26 | list<string>::iterator it; |
hlipka | 0:4a32b2fce260 | 27 | for ( it=ids->begin() ; it != ids->end(); it++ ) |
hlipka | 0:4a32b2fce260 | 28 | { |
hlipka | 0:4a32b2fce260 | 29 | printf("id=%s\n",(*it).c_str()); |
hlipka | 0:4a32b2fce260 | 30 | |
hlipka | 0:4a32b2fce260 | 31 | Pop3Message *msg=p3->getMessage(*it); |
hlipka | 0:4a32b2fce260 | 32 | if (NULL==msg) |
hlipka | 0:4a32b2fce260 | 33 | continue; |
hlipka | 0:4a32b2fce260 | 34 | printf("from %s\n",msg->from.c_str()); |
hlipka | 0:4a32b2fce260 | 35 | printf("subj %s\n",msg->subject.c_str()); |
hlipka | 0:4a32b2fce260 | 36 | |
hlipka | 0:4a32b2fce260 | 37 | p3->deleteMessage(*it); |
hlipka | 0:4a32b2fce260 | 38 | |
hlipka | 0:4a32b2fce260 | 39 | delete msg; |
hlipka | 0:4a32b2fce260 | 40 | |
hlipka | 0:4a32b2fce260 | 41 | } |
hlipka | 0:4a32b2fce260 | 42 | delete ids; |
hlipka | 0:4a32b2fce260 | 43 | } |
hlipka | 0:4a32b2fce260 | 44 | p3->close(); |
hlipka | 0:4a32b2fce260 | 45 | delete p3; |
hlipka | 0:4a32b2fce260 | 46 | } |