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:
Fri Feb 18 13:57:55 2011 +0000
Revision:
6:3e29a3a6f3bb
Parent:
3:37570217ae90
added license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 6:3e29a3a6f3bb 1 /*
hlipka 6:3e29a3a6f3bb 2 * POP3 library
hlipka 6:3e29a3a6f3bb 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 6:3e29a3a6f3bb 4 *
hlipka 6:3e29a3a6f3bb 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 6:3e29a3a6f3bb 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 6:3e29a3a6f3bb 7 * in the Software without restriction, including without limitation the rights
hlipka 6:3e29a3a6f3bb 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 6:3e29a3a6f3bb 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 6:3e29a3a6f3bb 10 * furnished to do so, subject to the following conditions:
hlipka 6:3e29a3a6f3bb 11 *
hlipka 6:3e29a3a6f3bb 12 * The above copyright notice and this permission notice shall be included in
hlipka 6:3e29a3a6f3bb 13 * all copies or substantial portions of the Software.
hlipka 6:3e29a3a6f3bb 14 *
hlipka 6:3e29a3a6f3bb 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 6:3e29a3a6f3bb 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 6:3e29a3a6f3bb 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 6:3e29a3a6f3bb 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 6:3e29a3a6f3bb 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 6:3e29a3a6f3bb 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 6:3e29a3a6f3bb 21 * THE SOFTWARE.
hlipka 6:3e29a3a6f3bb 22 */
hlipka 6:3e29a3a6f3bb 23
hlipka 0:ec8a3cef200d 24 #ifndef __POP3_H__
hlipka 0:ec8a3cef200d 25 #define __POP3_H__
hlipka 0:ec8a3cef200d 26
hlipka 0:ec8a3cef200d 27 #include <string>
hlipka 0:ec8a3cef200d 28 #include <list>
hlipka 0:ec8a3cef200d 29
hlipka 2:3893c1aaee8d 30 #include "tcplinestream.h"
hlipka 0:ec8a3cef200d 31
hlipka 0:ec8a3cef200d 32 using namespace std;
hlipka 0:ec8a3cef200d 33
hlipka 0:ec8a3cef200d 34 /**
hlipka 0:ec8a3cef200d 35 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 36 */
hlipka 0:ec8a3cef200d 37 class Pop3Message
hlipka 0:ec8a3cef200d 38 {
hlipka 0:ec8a3cef200d 39 public:
hlipka 0:ec8a3cef200d 40 /**
hlipka 3:37570217ae90 41 the UIDL this message has on the server
hlipka 3:37570217ae90 42 */
hlipka 3:37570217ae90 43 string id;
hlipka 3:37570217ae90 44 /**
hlipka 0:ec8a3cef200d 45 the 'From:' header
hlipka 0:ec8a3cef200d 46 */
hlipka 0:ec8a3cef200d 47 string from;
hlipka 0:ec8a3cef200d 48 /**
hlipka 0:ec8a3cef200d 49 the 'Subject:' header
hlipka 0:ec8a3cef200d 50 */
hlipka 0:ec8a3cef200d 51 string subject;
hlipka 0:ec8a3cef200d 52 /**
hlipka 0:ec8a3cef200d 53 the actual mail content, line by line
hlipka 0:ec8a3cef200d 54 */
hlipka 0:ec8a3cef200d 55 list<string> content;
hlipka 3:37570217ae90 56
hlipka 0:ec8a3cef200d 57 };
hlipka 0:ec8a3cef200d 58
hlipka 0:ec8a3cef200d 59 class Pop3CommandResponse;
hlipka 0:ec8a3cef200d 60
hlipka 0:ec8a3cef200d 61 /**
hlipka 0:ec8a3cef200d 62 Handling all POP3 related aspects. All operations are synchronous. This class expects a set-up network connection.
hlipka 0:ec8a3cef200d 63
hlipka 0:ec8a3cef200d 64 Needed libraries:
hlipka 0:ec8a3cef200d 65 * DNSResolver
hlipka 0:ec8a3cef200d 66 * NetServices (for TCP socket), or NetServicesMin
hlipka 0:ec8a3cef200d 67 */
hlipka 0:ec8a3cef200d 68 class Pop3
hlipka 0:ec8a3cef200d 69 {
hlipka 0:ec8a3cef200d 70 public:
hlipka 0:ec8a3cef200d 71 /**
hlipka 0:ec8a3cef200d 72 Creates the POP3 handler
hlipka 0:ec8a3cef200d 73
hlipka 0:ec8a3cef200d 74 @param servername the DNS name of the server
hlipka 0:ec8a3cef200d 75 @param username the username
hlipka 0:ec8a3cef200d 76 @param password the users password
hlipka 0:ec8a3cef200d 77 */
hlipka 0:ec8a3cef200d 78 Pop3(const char* servername, const char* username, const char* password);
hlipka 0:ec8a3cef200d 79
hlipka 0:ec8a3cef200d 80 /**
hlipka 0:ec8a3cef200d 81 closes the connection, and cleans up resources
hlipka 0:ec8a3cef200d 82 */
hlipka 0:ec8a3cef200d 83 ~Pop3();
hlipka 0:ec8a3cef200d 84
hlipka 0:ec8a3cef200d 85 /**
hlipka 0:ec8a3cef200d 86 Retrieve a list of all message IDs. This method doesn't care whether the messages have been read already or not.
hlipka 0:ec8a3cef200d 87 The IDs are not sorted, but returned in the order the server delivers them.
hlipka 0:ec8a3cef200d 88
hlipka 0:ec8a3cef200d 89 @return the list of all message IDs stored at the server.
hlipka 0:ec8a3cef200d 90 */
hlipka 0:ec8a3cef200d 91 list<string> *getMessages();
hlipka 0:ec8a3cef200d 92
hlipka 0:ec8a3cef200d 93 /**
hlipka 0:ec8a3cef200d 94 retrieves as single message
hlipka 0:ec8a3cef200d 95
hlipka 0:ec8a3cef200d 96 @param id the message ID to retrieve
hlipka 0:ec8a3cef200d 97 @param getSig when false, the signature will be stripped (separated by the line '-- ')
hlipka 0:ec8a3cef200d 98 @param deleteOnReceive when true the message will be deleted after a sucessful retrieval
hlipka 0:ec8a3cef200d 99 @return the message container
hlipka 0:ec8a3cef200d 100 */
hlipka 0:ec8a3cef200d 101 Pop3Message* getMessage(string id, bool getSig=false, bool deleteOnReceive=false);
hlipka 0:ec8a3cef200d 102
hlipka 0:ec8a3cef200d 103 /**
hlipka 0:ec8a3cef200d 104 @param id the ID of the message to be deleted
hlipka 0:ec8a3cef200d 105 @return true if the deletion was sucessful
hlipka 0:ec8a3cef200d 106 */
hlipka 0:ec8a3cef200d 107 bool deleteMessage(string id);
hlipka 0:ec8a3cef200d 108
hlipka 0:ec8a3cef200d 109 /**
hlipka 0:ec8a3cef200d 110 Connects to the server. Needs the ethernet connection already set up.
hlipka 0:ec8a3cef200d 111
hlipka 0:ec8a3cef200d 112 @return true if the connection has been made (and the user logged in)
hlipka 0:ec8a3cef200d 113 */
hlipka 0:ec8a3cef200d 114 bool init();
hlipka 0:ec8a3cef200d 115
hlipka 0:ec8a3cef200d 116 /**
hlipka 0:ec8a3cef200d 117 closes the connection, and cleans up resources
hlipka 0:ec8a3cef200d 118 */
hlipka 0:ec8a3cef200d 119 void close();
hlipka 0:ec8a3cef200d 120
hlipka 0:ec8a3cef200d 121 private:
hlipka 0:ec8a3cef200d 122 Pop3CommandResponse* sendCommand(string cmd);
hlipka 0:ec8a3cef200d 123 Pop3CommandResponse* sendCommandMultiResponse(string cmd);
hlipka 0:ec8a3cef200d 124
hlipka 2:3893c1aaee8d 125 TCPLineStream *_stream;
hlipka 0:ec8a3cef200d 126
hlipka 0:ec8a3cef200d 127 const char* _username;
hlipka 0:ec8a3cef200d 128 const char* _password;
hlipka 0:ec8a3cef200d 129 const char* _servername;
hlipka 0:ec8a3cef200d 130
hlipka 2:3893c1aaee8d 131 bool _closed;
hlipka 0:ec8a3cef200d 132 };
hlipka 0:ec8a3cef200d 133
hlipka 0:ec8a3cef200d 134
hlipka 0:ec8a3cef200d 135 #endif