Small library for reading mail messages via POP3. Currently doesn\'t return all header fields, and does only plain text authorization.

Dependents:   mmain pop3demo

Committer:
hlipka
Date:
Sat Jan 29 23:27:26 2011 +0000
Revision:
2:3893c1aaee8d
Parent:
1:f2b05d1c91be
Child:
3:37570217ae90
changed to use the TcpLineStream library - makes it simples and faster

Who changed what in which revision?

UserRevisionLine numberNew 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 0:ec8a3cef200d 18 the 'From:' header
hlipka 0:ec8a3cef200d 19 */
hlipka 0:ec8a3cef200d 20 string from;
hlipka 0:ec8a3cef200d 21 /**
hlipka 0:ec8a3cef200d 22 the 'Subject:' header
hlipka 0:ec8a3cef200d 23 */
hlipka 0:ec8a3cef200d 24 string subject;
hlipka 0:ec8a3cef200d 25 /**
hlipka 0:ec8a3cef200d 26 the actual mail content, line by line
hlipka 0:ec8a3cef200d 27 */
hlipka 0:ec8a3cef200d 28 list<string> content;
hlipka 0:ec8a3cef200d 29 };
hlipka 0:ec8a3cef200d 30
hlipka 0:ec8a3cef200d 31 class Pop3CommandResponse;
hlipka 0:ec8a3cef200d 32
hlipka 0:ec8a3cef200d 33 /**
hlipka 0:ec8a3cef200d 34 Handling all POP3 related aspects. All operations are synchronous. This class expects a set-up network connection.
hlipka 0:ec8a3cef200d 35
hlipka 0:ec8a3cef200d 36 Needed libraries:
hlipka 0:ec8a3cef200d 37 * DNSResolver
hlipka 0:ec8a3cef200d 38 * NetServices (for TCP socket), or NetServicesMin
hlipka 0:ec8a3cef200d 39 */
hlipka 0:ec8a3cef200d 40 class Pop3
hlipka 0:ec8a3cef200d 41 {
hlipka 0:ec8a3cef200d 42 public:
hlipka 0:ec8a3cef200d 43 /**
hlipka 0:ec8a3cef200d 44 Creates the POP3 handler
hlipka 0:ec8a3cef200d 45
hlipka 0:ec8a3cef200d 46 @param servername the DNS name of the server
hlipka 0:ec8a3cef200d 47 @param username the username
hlipka 0:ec8a3cef200d 48 @param password the users password
hlipka 0:ec8a3cef200d 49 */
hlipka 0:ec8a3cef200d 50 Pop3(const char* servername, const char* username, const char* password);
hlipka 0:ec8a3cef200d 51
hlipka 0:ec8a3cef200d 52 /**
hlipka 0:ec8a3cef200d 53 closes the connection, and cleans up resources
hlipka 0:ec8a3cef200d 54 */
hlipka 0:ec8a3cef200d 55 ~Pop3();
hlipka 0:ec8a3cef200d 56
hlipka 0:ec8a3cef200d 57 /**
hlipka 0:ec8a3cef200d 58 Retrieve a list of all message IDs. This method doesn't care whether the messages have been read already or not.
hlipka 0:ec8a3cef200d 59 The IDs are not sorted, but returned in the order the server delivers them.
hlipka 0:ec8a3cef200d 60
hlipka 0:ec8a3cef200d 61 @return the list of all message IDs stored at the server.
hlipka 0:ec8a3cef200d 62 */
hlipka 0:ec8a3cef200d 63 list<string> *getMessages();
hlipka 0:ec8a3cef200d 64
hlipka 0:ec8a3cef200d 65 /**
hlipka 0:ec8a3cef200d 66 retrieves as single message
hlipka 0:ec8a3cef200d 67
hlipka 0:ec8a3cef200d 68 @param id the message ID to retrieve
hlipka 0:ec8a3cef200d 69 @param getSig when false, the signature will be stripped (separated by the line '-- ')
hlipka 0:ec8a3cef200d 70 @param deleteOnReceive when true the message will be deleted after a sucessful retrieval
hlipka 0:ec8a3cef200d 71 @return the message container
hlipka 0:ec8a3cef200d 72 */
hlipka 0:ec8a3cef200d 73 Pop3Message* getMessage(string id, bool getSig=false, bool deleteOnReceive=false);
hlipka 0:ec8a3cef200d 74
hlipka 0:ec8a3cef200d 75 /**
hlipka 0:ec8a3cef200d 76 @param id the ID of the message to be deleted
hlipka 0:ec8a3cef200d 77 @return true if the deletion was sucessful
hlipka 0:ec8a3cef200d 78 */
hlipka 0:ec8a3cef200d 79 bool deleteMessage(string id);
hlipka 0:ec8a3cef200d 80
hlipka 0:ec8a3cef200d 81 /**
hlipka 0:ec8a3cef200d 82 Connects to the server. Needs the ethernet connection already set up.
hlipka 0:ec8a3cef200d 83
hlipka 0:ec8a3cef200d 84 @return true if the connection has been made (and the user logged in)
hlipka 0:ec8a3cef200d 85 */
hlipka 0:ec8a3cef200d 86 bool init();
hlipka 0:ec8a3cef200d 87
hlipka 0:ec8a3cef200d 88 /**
hlipka 0:ec8a3cef200d 89 closes the connection, and cleans up resources
hlipka 0:ec8a3cef200d 90 */
hlipka 0:ec8a3cef200d 91 void close();
hlipka 0:ec8a3cef200d 92
hlipka 0:ec8a3cef200d 93 private:
hlipka 0:ec8a3cef200d 94 Pop3CommandResponse* sendCommand(string cmd);
hlipka 0:ec8a3cef200d 95 Pop3CommandResponse* sendCommandMultiResponse(string cmd);
hlipka 0:ec8a3cef200d 96
hlipka 2:3893c1aaee8d 97 TCPLineStream *_stream;
hlipka 0:ec8a3cef200d 98
hlipka 0:ec8a3cef200d 99 const char* _username;
hlipka 0:ec8a3cef200d 100 const char* _password;
hlipka 0:ec8a3cef200d 101 const char* _servername;
hlipka 0:ec8a3cef200d 102
hlipka 2:3893c1aaee8d 103 bool _closed;
hlipka 0:ec8a3cef200d 104 };
hlipka 0:ec8a3cef200d 105
hlipka 0:ec8a3cef200d 106
hlipka 0:ec8a3cef200d 107 #endif