Small library for reading mail messages via POP3. Currently doesn\'t return all header fields, and does only plain text authorization.
pop3.h@3:37570217ae90, 2011-02-01 (annotated)
- Committer:
- hlipka
- Date:
- Tue Feb 01 21:17:03 2011 +0000
- Revision:
- 3:37570217ae90
- Parent:
- 2:3893c1aaee8d
- Child:
- 6:3e29a3a6f3bb
Now using UIDL as message ID, since the normal ID is not unique (between sessions). Also, now closes the session properly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:ec8a3cef200d | 1 | #ifndef __POP3_H__ |
hlipka | 0:ec8a3cef200d | 2 | #define __POP3_H__ |
hlipka | 0:ec8a3cef200d | 3 | |
hlipka | 0:ec8a3cef200d | 4 | #include <string> |
hlipka | 0:ec8a3cef200d | 5 | #include <list> |
hlipka | 0:ec8a3cef200d | 6 | |
hlipka | 2:3893c1aaee8d | 7 | #include "tcplinestream.h" |
hlipka | 0:ec8a3cef200d | 8 | |
hlipka | 0:ec8a3cef200d | 9 | using namespace std; |
hlipka | 0:ec8a3cef200d | 10 | |
hlipka | 0:ec8a3cef200d | 11 | /** |
hlipka | 0:ec8a3cef200d | 12 | The class representing a received mail message. All fields are stored in un-altered form, so character set conversion might need to be performed. |
hlipka | 0:ec8a3cef200d | 13 | */ |
hlipka | 0:ec8a3cef200d | 14 | class Pop3Message |
hlipka | 0:ec8a3cef200d | 15 | { |
hlipka | 0:ec8a3cef200d | 16 | public: |
hlipka | 0:ec8a3cef200d | 17 | /** |
hlipka | 3:37570217ae90 | 18 | the UIDL this message has on the server |
hlipka | 3:37570217ae90 | 19 | */ |
hlipka | 3:37570217ae90 | 20 | string id; |
hlipka | 3:37570217ae90 | 21 | /** |
hlipka | 0:ec8a3cef200d | 22 | the 'From:' header |
hlipka | 0:ec8a3cef200d | 23 | */ |
hlipka | 0:ec8a3cef200d | 24 | string from; |
hlipka | 0:ec8a3cef200d | 25 | /** |
hlipka | 0:ec8a3cef200d | 26 | the 'Subject:' header |
hlipka | 0:ec8a3cef200d | 27 | */ |
hlipka | 0:ec8a3cef200d | 28 | string subject; |
hlipka | 0:ec8a3cef200d | 29 | /** |
hlipka | 0:ec8a3cef200d | 30 | the actual mail content, line by line |
hlipka | 0:ec8a3cef200d | 31 | */ |
hlipka | 0:ec8a3cef200d | 32 | list<string> content; |
hlipka | 3:37570217ae90 | 33 | |
hlipka | 0:ec8a3cef200d | 34 | }; |
hlipka | 0:ec8a3cef200d | 35 | |
hlipka | 0:ec8a3cef200d | 36 | class Pop3CommandResponse; |
hlipka | 0:ec8a3cef200d | 37 | |
hlipka | 0:ec8a3cef200d | 38 | /** |
hlipka | 0:ec8a3cef200d | 39 | Handling all POP3 related aspects. All operations are synchronous. This class expects a set-up network connection. |
hlipka | 0:ec8a3cef200d | 40 | |
hlipka | 0:ec8a3cef200d | 41 | Needed libraries: |
hlipka | 0:ec8a3cef200d | 42 | * DNSResolver |
hlipka | 0:ec8a3cef200d | 43 | * NetServices (for TCP socket), or NetServicesMin |
hlipka | 0:ec8a3cef200d | 44 | */ |
hlipka | 0:ec8a3cef200d | 45 | class Pop3 |
hlipka | 0:ec8a3cef200d | 46 | { |
hlipka | 0:ec8a3cef200d | 47 | public: |
hlipka | 0:ec8a3cef200d | 48 | /** |
hlipka | 0:ec8a3cef200d | 49 | Creates the POP3 handler |
hlipka | 0:ec8a3cef200d | 50 | |
hlipka | 0:ec8a3cef200d | 51 | @param servername the DNS name of the server |
hlipka | 0:ec8a3cef200d | 52 | @param username the username |
hlipka | 0:ec8a3cef200d | 53 | @param password the users password |
hlipka | 0:ec8a3cef200d | 54 | */ |
hlipka | 0:ec8a3cef200d | 55 | Pop3(const char* servername, const char* username, const char* password); |
hlipka | 0:ec8a3cef200d | 56 | |
hlipka | 0:ec8a3cef200d | 57 | /** |
hlipka | 0:ec8a3cef200d | 58 | closes the connection, and cleans up resources |
hlipka | 0:ec8a3cef200d | 59 | */ |
hlipka | 0:ec8a3cef200d | 60 | ~Pop3(); |
hlipka | 0:ec8a3cef200d | 61 | |
hlipka | 0:ec8a3cef200d | 62 | /** |
hlipka | 0:ec8a3cef200d | 63 | Retrieve a list of all message IDs. This method doesn't care whether the messages have been read already or not. |
hlipka | 0:ec8a3cef200d | 64 | The IDs are not sorted, but returned in the order the server delivers them. |
hlipka | 0:ec8a3cef200d | 65 | |
hlipka | 0:ec8a3cef200d | 66 | @return the list of all message IDs stored at the server. |
hlipka | 0:ec8a3cef200d | 67 | */ |
hlipka | 0:ec8a3cef200d | 68 | list<string> *getMessages(); |
hlipka | 0:ec8a3cef200d | 69 | |
hlipka | 0:ec8a3cef200d | 70 | /** |
hlipka | 0:ec8a3cef200d | 71 | retrieves as single message |
hlipka | 0:ec8a3cef200d | 72 | |
hlipka | 0:ec8a3cef200d | 73 | @param id the message ID to retrieve |
hlipka | 0:ec8a3cef200d | 74 | @param getSig when false, the signature will be stripped (separated by the line '-- ') |
hlipka | 0:ec8a3cef200d | 75 | @param deleteOnReceive when true the message will be deleted after a sucessful retrieval |
hlipka | 0:ec8a3cef200d | 76 | @return the message container |
hlipka | 0:ec8a3cef200d | 77 | */ |
hlipka | 0:ec8a3cef200d | 78 | Pop3Message* getMessage(string id, bool getSig=false, bool deleteOnReceive=false); |
hlipka | 0:ec8a3cef200d | 79 | |
hlipka | 0:ec8a3cef200d | 80 | /** |
hlipka | 0:ec8a3cef200d | 81 | @param id the ID of the message to be deleted |
hlipka | 0:ec8a3cef200d | 82 | @return true if the deletion was sucessful |
hlipka | 0:ec8a3cef200d | 83 | */ |
hlipka | 0:ec8a3cef200d | 84 | bool deleteMessage(string id); |
hlipka | 0:ec8a3cef200d | 85 | |
hlipka | 0:ec8a3cef200d | 86 | /** |
hlipka | 0:ec8a3cef200d | 87 | Connects to the server. Needs the ethernet connection already set up. |
hlipka | 0:ec8a3cef200d | 88 | |
hlipka | 0:ec8a3cef200d | 89 | @return true if the connection has been made (and the user logged in) |
hlipka | 0:ec8a3cef200d | 90 | */ |
hlipka | 0:ec8a3cef200d | 91 | bool init(); |
hlipka | 0:ec8a3cef200d | 92 | |
hlipka | 0:ec8a3cef200d | 93 | /** |
hlipka | 0:ec8a3cef200d | 94 | closes the connection, and cleans up resources |
hlipka | 0:ec8a3cef200d | 95 | */ |
hlipka | 0:ec8a3cef200d | 96 | void close(); |
hlipka | 0:ec8a3cef200d | 97 | |
hlipka | 0:ec8a3cef200d | 98 | private: |
hlipka | 0:ec8a3cef200d | 99 | Pop3CommandResponse* sendCommand(string cmd); |
hlipka | 0:ec8a3cef200d | 100 | Pop3CommandResponse* sendCommandMultiResponse(string cmd); |
hlipka | 0:ec8a3cef200d | 101 | |
hlipka | 2:3893c1aaee8d | 102 | TCPLineStream *_stream; |
hlipka | 0:ec8a3cef200d | 103 | |
hlipka | 0:ec8a3cef200d | 104 | const char* _username; |
hlipka | 0:ec8a3cef200d | 105 | const char* _password; |
hlipka | 0:ec8a3cef200d | 106 | const char* _servername; |
hlipka | 0:ec8a3cef200d | 107 | |
hlipka | 2:3893c1aaee8d | 108 | bool _closed; |
hlipka | 0:ec8a3cef200d | 109 | }; |
hlipka | 0:ec8a3cef200d | 110 | |
hlipka | 0:ec8a3cef200d | 111 | |
hlipka | 0:ec8a3cef200d | 112 | #endif |