2011-04-10 [colin] 3.7.9cvs7
[claws.git] / src / pop.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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         guint data_len;
44 };
45 typedef struct _MailReceiveData MailReceiveData;
46
47 typedef enum {
48         POP3_READY,
49         POP3_GREETING,
50 #ifdef USE_GNUTLS
51         POP3_STLS,
52 #endif
53         POP3_GETAUTH_USER,
54         POP3_GETAUTH_PASS,
55         POP3_GETAUTH_APOP,
56         POP3_GETRANGE_STAT,
57         POP3_GETRANGE_LAST,
58         POP3_GETRANGE_UIDL,
59         POP3_GETRANGE_UIDL_RECV,
60         POP3_GETSIZE_LIST,
61         POP3_GETSIZE_LIST_RECV,
62         POP3_RETR,
63         POP3_RETR_RECV,
64         POP3_TOP,
65         POP3_TOP_RECV,
66         POP3_DELETE,
67         POP3_LOGOUT,
68         POP3_DONE,
69         POP3_ERROR,
70
71         N_POP3_STATE
72 } Pop3State;
73
74 typedef enum {
75         PS_SUCCESS      = 0,    /* command successful */
76         PS_NOMAIL       = 1,    /* no mail available */
77         PS_SOCKET       = 2,    /* socket I/O woes */
78         PS_AUTHFAIL     = 3,    /* user authorization failed */
79         PS_PROTOCOL     = 4,    /* protocol violation */
80         PS_SYNTAX       = 5,    /* command-line syntax error */
81         PS_IOERR        = 6,    /* file I/O error */
82         PS_ERROR        = 7,    /* protocol error */
83         PS_EXCLUDE      = 8,    /* client-side exclusion error */
84         PS_LOCKBUSY     = 9,    /* server responded lock busy */
85         PS_SMTP         = 10,   /* SMTP error */
86         PS_DNS          = 11,   /* fatal DNS error */
87         PS_BSMTP        = 12,   /* output batch could not be opened */
88         PS_MAXFETCH     = 13,   /* poll ended by fetch limit */
89
90         PS_NOTSUPPORTED = 14,   /* command not supported */
91
92         /* leave space for more codes */
93
94         PS_CONTINUE     = 128   /* more responses may follow */
95 } Pop3ErrorValue;
96
97 typedef enum {
98         RECV_TIME_NONE     = 0,
99         RECV_TIME_RECEIVED = 1,
100         RECV_TIME_KEEP     = 2
101 } RecvTime;
102
103 struct _Pop3MsgInfo
104 {
105         gint size;
106         gchar *uidl;
107         time_t recv_time;
108         guint received     : 1;
109         guint deleted      : 1;
110         guint partial_recv : 2;
111 };
112
113 struct _Pop3Session
114 {
115         Session session;
116
117         Pop3State state;
118         gchar *prev_folder;
119
120         PrefsAccount *ac_prefs;
121         gboolean pop_before_smtp;
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         GHashTable *partial_recv_table;
137         
138         gboolean new_msg_exist;
139         gboolean uidl_is_valid;
140
141         time_t current_time;
142
143         Pop3ErrorValue error_val;
144         gchar *error_msg;
145
146         gpointer data;
147
148         /* virtual method to drop message */
149         gint (*drop_message)    (Pop3Session    *session,
150                                  const gchar    *file);
151 };
152
153 #define POPBUFSIZE      512
154 /* #define IDLEN        128 */
155 #define IDLEN           POPBUFSIZE
156
157 Session *pop3_session_new       (PrefsAccount   *account);
158 gint pop3_write_uidl_list       (Pop3Session    *session);
159
160 #endif /* __POP_H__ */