0.9.4claws65
[claws.git] / src / pop.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __POP_H__
21 #define __POP_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28 #include <time.h>
29
30 #include "session.h"
31 #include "prefs_account.h"
32
33 typedef struct _Pop3MsgInfo     Pop3MsgInfo;
34 typedef struct _Pop3Session     Pop3Session;
35
36 #define POP3_SESSION(obj)       ((Pop3Session *)obj)
37
38 #define MAIL_RECEIVE_HOOKLIST   "mail_receive_hooklist"
39 struct _MailReceiveData
40 {
41         Pop3Session *session;
42         char *data;
43 };
44 typedef struct _MailReceiveData MailReceiveData;
45
46 typedef enum {
47         POP3_READY,
48         POP3_GREETING,
49 #if USE_OPENSSL
50         POP3_STLS,
51 #endif
52         POP3_GETAUTH_USER,
53         POP3_GETAUTH_PASS,
54         POP3_GETAUTH_APOP,
55         POP3_GETRANGE_STAT,
56         POP3_GETRANGE_LAST,
57         POP3_GETRANGE_UIDL,
58         POP3_GETRANGE_UIDL_RECV,
59         POP3_GETSIZE_LIST,
60         POP3_GETSIZE_LIST_RECV,
61         POP3_RETR,
62         POP3_RETR_RECV,
63         POP3_DELETE,
64         POP3_LOGOUT,
65         POP3_ERROR,
66
67         N_POP3_STATE
68 } Pop3State;
69
70 typedef enum {
71         PS_SUCCESS      = 0,    /* command successful */
72         PS_NOMAIL       = 1,    /* no mail available */
73         PS_SOCKET       = 2,    /* socket I/O woes */
74         PS_AUTHFAIL     = 3,    /* user authorization failed */
75         PS_PROTOCOL     = 4,    /* protocol violation */
76         PS_SYNTAX       = 5,    /* command-line syntax error */
77         PS_IOERR        = 6,    /* file I/O error */
78         PS_ERROR        = 7,    /* protocol error */
79         PS_EXCLUDE      = 8,    /* client-side exclusion error */
80         PS_LOCKBUSY     = 9,    /* server responded lock busy */
81         PS_SMTP         = 10,   /* SMTP error */
82         PS_DNS          = 11,   /* fatal DNS error */
83         PS_BSMTP        = 12,   /* output batch could not be opened */
84         PS_MAXFETCH     = 13,   /* poll ended by fetch limit */
85
86         PS_NOTSUPPORTED = 14,   /* command not supported */
87
88         /* leave space for more codes */
89
90         PS_UNDEFINED    = 23,   /* something I hadn't thought of */
91         PS_TRANSIENT    = 24,   /* transient failure (internal use) */
92         PS_REFUSED      = 25,   /* mail refused (internal use) */
93         PS_RETAINED     = 26,   /* message retained (internal use) */
94         PS_TRUNCATED    = 27,   /* headers incomplete (internal use) */
95
96         PS_CONTINUE     = 128   /* more responses may follow */
97 } Pop3ErrorValue;
98
99 typedef enum {
100         RECV_TIME_NONE     = 0,
101         RECV_TIME_RECEIVED = 1,
102         RECV_TIME_KEEP     = 2
103 } RecvTime;
104
105 struct _Pop3MsgInfo
106 {
107         gint size;
108         gchar *uidl;
109         time_t recv_time;
110         guint received : 1;
111         guint deleted  : 1;
112 };
113
114 struct _Pop3Session
115 {
116         Session session;
117
118         Pop3State state;
119         gchar *prev_folder;
120
121         PrefsAccount *ac_prefs;
122
123         gchar *greeting;
124         gchar *user;
125         gchar *pass;
126         gint count;
127         gint total_bytes;
128         gint cur_msg;
129         gint cur_total_num;
130         gint cur_total_bytes;
131         gint cur_total_recv_bytes;
132
133         Pop3MsgInfo *msg;
134
135         GHashTable *uidl_table;
136
137         gboolean new_msg_exist;
138         gboolean uidl_is_valid;
139
140         time_t current_time;
141
142         Pop3ErrorValue error_val;
143         gchar *error_msg;
144
145         gpointer data;
146 };
147
148 #define POPBUFSIZE      512
149 #define IDLEN           128
150
151
152 Session *pop3_session_new       (PrefsAccount   *account);
153 GHashTable *pop3_get_uidl_table (PrefsAccount   *account);
154 gint pop3_write_uidl_list       (Pop3Session    *session);
155
156 #endif /* __POP_H__ */