sptk2 logo
SPTK Home Page
ImapConnect.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/FieldList.h>
30#include <sptk5/Strings.h>
31#include <sptk5/net/TCPSocket.h>
32
33#include <string>
34
35namespace sptk {
36
49class SP_EXPORT ImapConnect : public TCPSocket
50{
51public:
55 ImapConnect() = default;
56
64 void command(const String& cmd, const String& arg1 = "", const String& arg2 = "");
65
69 const Strings& response() const
70 {
71 return m_response;
72 }
73
80 {
81 command("capability");
82 }
83
87 void cmd_noop()
88 {
89 command("noop");
90 }
91
96 {
97 command("LOGOUT");
98 }
99
100 // IMAPv4 commands - not logged in
101
108 void cmd_login(const String& user, const String& password);
109
110 // IMAPv4 commands - logged in, mailbox-operations
111
117 void cmd_select(const String& mail_box, int32_t& total_msgs);
118
123 void cmd_examine(const String& mail_box)
124 {
125 command("examine", mail_box);
126 }
127
132 void cmd_subscribe(const String& mail_box)
133 {
134 command("subscribe", mail_box);
135 }
136
141 void cmd_unsubscribe(const String& mail_box)
142 {
143 command("unsubscribe", mail_box);
144 }
145
150 void cmd_create(const String& mail_box)
151 {
152 command("create", mail_box);
153 }
154
159 void cmd_delete(const String& mail_box)
160 {
161 command("delete", mail_box);
162 }
163
169 void cmd_rename(const String& mail_box, const String& new_name)
170 {
171 command("rename ", mail_box, new_name);
172 }
173
179 void cmd_list(const String& mail_box_mask, bool decode = false);
180
186 void cmd_append(const String& mail_box, const Buffer& message);
187
188 // IMAPv4 commands - logged in, selected mailbox-operations
189
194 {
195 command("close");
196 }
197
202 {
203 command("expunge");
204 }
205
209 void cmd_search_all(String& result);
210
214 void cmd_search_new(String& result);
215
221 void cmd_fetch_headers(int32_t msg_id, FieldList& result);
222
228 void cmd_fetch_message(int32_t msg_id, FieldList& result);
229
235 String cmd_fetch_flags(int32_t msg_id);
236
242 void cmd_store_flags(int32_t msg_id, const char* flags);
243
244protected:
253
258 bool getResponse(const String& ident);
259
264 void parseSearch(String& result) const;
265
271 void parseMessage(FieldList& result, bool headersOnly);
272
279
280private:
281 Strings m_response;
282 int32_t m_ident {1};
283 static const String empty_quotes;
284};
285
289} // namespace sptk
Definition: Buffer.h:51
Definition: FieldList.h:50
Definition: ImapConnect.h:50
void parseMessage(FieldList &result, bool headersOnly)
void command(const String &cmd, const String &arg1="", const String &arg2="")
ImapConnect()=default
void cmd_fetch_message(int32_t msg_id, FieldList &result)
void cmd_subscribe(const String &mail_box)
Definition: ImapConnect.h:132
bool getResponse(const String &ident)
void cmd_capability()
Definition: ImapConnect.h:79
void cmd_list(const String &mail_box_mask, bool decode=false)
void cmd_delete(const String &mail_box)
Definition: ImapConnect.h:159
void cmd_expunge()
Definition: ImapConnect.h:201
void parseSearch(String &result) const
void cmd_login(const String &user, const String &password)
void cmd_rename(const String &mail_box, const String &new_name)
Definition: ImapConnect.h:169
void cmd_fetch_headers(int32_t msg_id, FieldList &result)
String sendCommand(const String &cmd)
void cmd_examine(const String &mail_box)
Definition: ImapConnect.h:123
void cmd_search_all(String &result)
void cmd_noop()
Definition: ImapConnect.h:87
void cmd_select(const String &mail_box, int32_t &total_msgs)
void cmd_close()
Definition: ImapConnect.h:193
void cmd_search_new(String &result)
const Strings & response() const
Definition: ImapConnect.h:69
String cmd_fetch_flags(int32_t msg_id)
void cmd_unsubscribe(const String &mail_box)
Definition: ImapConnect.h:141
void cmd_append(const String &mail_box, const Buffer &message)
void cmd_logout()
Definition: ImapConnect.h:95
void cmd_create(const String &mail_box)
Definition: ImapConnect.h:150
void cmd_store_flags(int32_t msg_id, const char *flags)
Definition: String.h:49
Definition: Strings.h:52
Definition: TCPSocket.h:165

Fri Oct 14 2022 09:58:32: SPTK 5.4.1