root / Community Core Vision / Windows / libs / poco / include / Poco / Net / POP3ClientSession.h @ 8

View | Annotate | Download (7.2 KB)

1 8 amit
//
2 8 amit
// POP3ClientSession.h
3 8 amit
//
4 8 amit
// $Id: //poco/1.3/Net/include/Poco/Net/POP3ClientSession.h#1 $
5 8 amit
//
6 8 amit
// Library: Net
7 8 amit
// Package: Mail
8 8 amit
// Module:  POP3ClientSession
9 8 amit
//
10 8 amit
// Definition of the POP3ClientSession class.
11 8 amit
//
12 8 amit
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13 8 amit
// and Contributors.
14 8 amit
//
15 8 amit
// Permission is hereby granted, free of charge, to any person or organization
16 8 amit
// obtaining a copy of the software and accompanying documentation covered by
17 8 amit
// this license (the "Software") to use, reproduce, display, distribute,
18 8 amit
// execute, and transmit the Software, and to prepare derivative works of the
19 8 amit
// Software, and to permit third-parties to whom the Software is furnished to
20 8 amit
// do so, all subject to the following:
21 8 amit
//
22 8 amit
// The copyright notices in the Software and this entire statement, including
23 8 amit
// the above license grant, this restriction and the following disclaimer,
24 8 amit
// must be included in all copies of the Software, in whole or in part, and
25 8 amit
// all derivative works of the Software, unless such copies or derivative
26 8 amit
// works are solely in the form of machine-executable object code generated by
27 8 amit
// a source language processor.
28 8 amit
//
29 8 amit
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 8 amit
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 8 amit
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 8 amit
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 8 amit
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 8 amit
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 8 amit
// DEALINGS IN THE SOFTWARE.
36 8 amit
//
37 8 amit
38 8 amit
39 8 amit
#ifndef Net_POP3ClientSession_INCLUDED
40 8 amit
#define Net_POP3ClientSession_INCLUDED
41 8 amit
42 8 amit
43 8 amit
#include "Poco/Net/Net.h"
44 8 amit
#include "Poco/Net/DialogSocket.h"
45 8 amit
#include "Poco/Timespan.h"
46 8 amit
#include <ostream>
47 8 amit
#include <vector>
48 8 amit
49 8 amit
50 8 amit
namespace Poco {
51 8 amit
namespace Net {
52 8 amit
53 8 amit
54 8 amit
class MessageHeader;
55 8 amit
class MailMessage;
56 8 amit
class PartHandler;
57 8 amit
58 8 amit
59 8 amit
class Net_API POP3ClientSession
60 8 amit
        /// This class implements an Post Office Protocol
61 8 amit
        /// Version 3 (POP3, RFC 1939)
62 8 amit
        /// client for receiving e-mail messages.
63 8 amit
{
64 8 amit
public:
65 8 amit
        enum
66 8 amit
        {
67 8 amit
                POP3_PORT = 110
68 8 amit
        };
69 8 amit
70 8 amit
        struct MessageInfo
71 8 amit
                /// Information returned by listMessages().
72 8 amit
        {
73 8 amit
                int id;
74 8 amit
                int size;
75 8 amit
        };
76 8 amit
77 8 amit
        typedef std::vector<MessageInfo> MessageInfoVec;
78 8 amit
79 8 amit
        POP3ClientSession(const StreamSocket& socket);
80 8 amit
                /// Creates the POP3ClientSession using
81 8 amit
                /// the given socket, which must be connected
82 8 amit
                /// to a POP3 server.
83 8 amit
84 8 amit
        POP3ClientSession(const std::string& host, Poco::UInt16 port = POP3_PORT);
85 8 amit
                /// Creates the POP3ClientSession using a socket connected
86 8 amit
                /// to the given host and port.
87 8 amit
88 8 amit
        virtual ~POP3ClientSession();
89 8 amit
                /// Destroys the SMTPClientSession.
90 8 amit
91 8 amit
        void setTimeout(const Poco::Timespan& timeout);
92 8 amit
                /// Sets the timeout for socket read operations.
93 8 amit
94 8 amit
        Poco::Timespan getTimeout() const;
95 8 amit
                /// Returns the timeout for socket read operations.
96 8 amit
97 8 amit
        void login(const std::string& username, const std::string& password);
98 8 amit
                /// Logs in to the POP3 server by sending a USER command
99 8 amit
                /// followed by a PASS command.
100 8 amit
                ///
101 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
102 8 amit
                /// NetException in case of a general network communication failure.
103 8 amit
104 8 amit
        void close();
105 8 amit
                /// Sends a QUIT command and closes the connection to the server.
106 8 amit
                ///
107 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
108 8 amit
                /// NetException in case of a general network communication failure.
109 8 amit
110 8 amit
        int messageCount();
111 8 amit
                /// Sends a STAT command to determine the number of messages
112 8 amit
                /// available on the server and returns that number.
113 8 amit
                ///
114 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
115 8 amit
                /// NetException in case of a general network communication failure.
116 8 amit
117 8 amit
        void listMessages(MessageInfoVec& messages);
118 8 amit
                /// Fills the given vector with the ids and sizes of all
119 8 amit
                /// messages available on the server.
120 8 amit
                ///
121 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
122 8 amit
                /// NetException in case of a general network communication failure.
123 8 amit
124 8 amit
        void retrieveMessage(int id, MailMessage& message);
125 8 amit
                /// Retrieves the message with the given id from the server and
126 8 amit
                /// stores the raw message content in the message's
127 8 amit
                /// content string, available with message.getContent().
128 8 amit
                ///
129 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
130 8 amit
                /// NetException in case of a general network communication failure.
131 8 amit
132 8 amit
        void retrieveMessage(int id, MailMessage& message, PartHandler& handler);
133 8 amit
                /// Retrieves the message with the given id from the server and
134 8 amit
                /// stores it in message.
135 8 amit
                ///
136 8 amit
                /// If the message has multiple parts, the parts
137 8 amit
                /// are reported to the PartHandler. If the message
138 8 amit
                /// is not a multi-part message, the content is stored
139 8 amit
                /// in a string available by calling message.getContent().
140 8 amit
                ///
141 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
142 8 amit
                /// NetException in case of a general network communication failure.
143 8 amit
144 8 amit
        void retrieveMessage(int id, std::ostream& ostr);
145 8 amit
                /// Retrieves the raw message with the given id from the
146 8 amit
                /// server and copies it to the given output stream.
147 8 amit
                ///
148 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
149 8 amit
                /// NetException in case of a general network communication failure.
150 8 amit
151 8 amit
        void retrieveHeader(int id, MessageHeader& header);
152 8 amit
                /// Retrieves the message header of the message with the
153 8 amit
                /// given id and stores it in header.
154 8 amit
                ///
155 8 amit
                /// For this to work, the server must support the TOP command.
156 8 amit
                ///
157 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
158 8 amit
                /// NetException in case of a general network communication failure.
159 8 amit
160 8 amit
        void deleteMessage(int id);
161 8 amit
                /// Marks the message with the given ID for deletion. The message
162 8 amit
                /// will be deleted when the connection to the server is
163 8 amit
                /// closed by calling close().
164 8 amit
                ///
165 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
166 8 amit
                /// NetException in case of a general network communication failure.
167 8 amit
168 8 amit
        bool sendCommand(const std::string& command, std::string& response);
169 8 amit
                /// Sends the given command verbatim to the server
170 8 amit
                /// and waits for a response.
171 8 amit
                ///
172 8 amit
                /// Returns true if the response is positive, false otherwise.
173 8 amit
                ///
174 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
175 8 amit
                /// NetException in case of a general network communication failure.
176 8 amit
177 8 amit
        bool sendCommand(const std::string& command, const std::string& arg, std::string& response);
178 8 amit
                /// Sends the given command verbatim to the server
179 8 amit
                /// and waits for a response.
180 8 amit
                ///
181 8 amit
                /// Returns true if the response is positive, false otherwise.
182 8 amit
                ///
183 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
184 8 amit
                /// NetException in case of a general network communication failure.
185 8 amit
186 8 amit
        bool sendCommand(const std::string& command, const std::string& arg1, const std::string& arg2, std::string& response);
187 8 amit
                /// Sends the given command verbatim to the server
188 8 amit
                /// and waits for a response.
189 8 amit
                ///
190 8 amit
                /// Returns true if the response is positive, false otherwise.
191 8 amit
                ///
192 8 amit
                /// Throws a POP3Exception in case of a POP3-specific error, or a
193 8 amit
                /// NetException in case of a general network communication failure.
194 8 amit
195 8 amit
protected:
196 8 amit
        static bool isPositive(const std::string& response);
197 8 amit
198 8 amit
private:
199 8 amit
        DialogSocket _socket;
200 8 amit
        bool         _isOpen;
201 8 amit
};
202 8 amit
203 8 amit
204 8 amit
} } // namespace Poco::Net
205 8 amit
206 8 amit
207 8 amit
#endif // Net_POP3ClientSession_INCLUDED