2 * Copyright (C) 2001 Ximian Inc.
4 * Authors: Michael Zucchi <notzed@ximian.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef _CAMEL_POP3_ENGINE_H
22 #define _CAMEL_POP3_ENGINE_H
24 #include <camel/camel-object.h>
25 #include <libedataserver/e-msgport.h>
26 #include "camel-pop3-stream.h"
28 #define CAMEL_POP3_ENGINE(obj) CAMEL_CHECK_CAST (obj, camel_pop3_engine_get_type (), CamelPOP3Engine)
29 #define CAMEL_POP3_ENGINE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_engine_get_type (), CamelPOP3EngineClass)
30 #define CAMEL_IS_POP3_ENGINE(obj) CAMEL_CHECK_TYPE (obj, camel_pop3_engine_get_type ())
34 typedef struct _CamelPOP3EngineClass CamelPOP3EngineClass;
35 typedef struct _CamelPOP3Engine CamelPOP3Engine;
36 typedef struct _CamelPOP3Command CamelPOP3Command;
38 /* pop 3 connection states, actually since we're given a connected socket, we always start in auth state */
40 CAMEL_POP3_ENGINE_DISCONNECT = 0,
41 CAMEL_POP3_ENGINE_AUTH,
42 CAMEL_POP3_ENGINE_TRANSACTION,
43 CAMEL_POP3_ENGINE_UPDATE,
44 } camel_pop3_engine_t;
46 /* state of a command */
48 CAMEL_POP3_COMMAND_IDLE = 0, /* command created or queued, not yet sent (e.g. non pipelined server) */
49 CAMEL_POP3_COMMAND_DISPATCHED, /* command sent to server */
51 /* completion codes */
52 CAMEL_POP3_COMMAND_OK, /* plain ok response */
53 CAMEL_POP3_COMMAND_DATA, /* processing command response */
54 CAMEL_POP3_COMMAND_ERR, /* error response */
55 } camel_pop3_command_t;
57 /* flags for command types */
59 CAMEL_POP3_COMMAND_SIMPLE = 0, /* dont expect multiline response */
60 CAMEL_POP3_COMMAND_MULTI = 1, /* expect multiline response */
63 /* flags for server options */
65 CAMEL_POP3_CAP_APOP = 1<<0,
66 CAMEL_POP3_CAP_UIDL = 1<<1,
67 CAMEL_POP3_CAP_SASL = 1<<2,
68 CAMEL_POP3_CAP_TOP = 1<<3,
69 CAMEL_POP3_CAP_PIPE = 1<<4,
70 CAMEL_POP3_CAP_STLS = 1<<5
73 /* enable/disable flags for the engine itself */
75 CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS = 1<<0,
78 typedef void (*CamelPOP3CommandFunc)(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data);
80 struct _CamelPOP3Command {
81 struct _CamelPOP3Command *next;
82 struct _CamelPOP3Command *prev;
85 camel_pop3_command_t state;
87 CamelPOP3CommandFunc func;
94 struct _CamelPOP3Engine {
99 camel_pop3_engine_t state;
101 GList *auth; /* authtypes supported */
103 guint32 capa; /* capabilities */
104 char *apop; /* apop time string */
106 unsigned char *line; /* current line buffer */
107 unsigned int linelen;
109 struct _CamelPOP3Stream *stream;
111 unsigned int sentlen; /* data sent (so we dont overflow network buffer) */
113 EDList active; /* active commands */
114 EDList queue; /* queue of waiting commands */
115 EDList done; /* list of done commands, awaiting free */
117 CamelPOP3Command *current; /* currently busy (downloading) response */
120 struct _CamelPOP3EngineClass {
121 CamelObjectClass parent_class;
124 CamelType camel_pop3_engine_get_type (void);
126 CamelPOP3Engine *camel_pop3_engine_new (CamelStream *source, guint32 flags);
128 void camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine);
130 void camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc);
132 int camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pc);
134 CamelPOP3Command *camel_pop3_engine_command_new (CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, void *data, const char *fmt, ...);
138 #endif /* ! _CAMEL_POP3_ENGINE_H */