044c77c284ae5a0a5e9c872807de84e12a1a27ee
[claws.git] / src / pop.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2004 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_TOP,
64         POP3_TOP_RECV,
65         POP3_DELETE,
66         POP3_LOGOUT,
67         POP3_ERROR,
68
69         N_POP3_STATE
70 } Pop3State;
71
72 typedef enum {
73         PS_SUCCESS      = 0,    /* command successful */
74         PS_NOMAIL       = 1,    /* no mail available */
75         PS_SOCKET       = 2,    /* socket I/O woes */
76         PS_AUTHFAIL     = 3,    /* user authorization failed */
77         PS_PROTOCOL     = 4,    /* protocol violation */
78         PS_SYNTAX       = 5,    /* command-line syntax error */
79         PS_IOERR        = 6,    /* file I/O error */
80         PS_ERROR        = 7,    /* protocol error */
81         PS_EXCLUDE      = 8,    /* client-side exclusion error */
82         PS_LOCKBUSY     = 9,    /* server responded lock busy */
83         PS_SMTP         = 10,   /* SMTP error */
84         PS_DNS          = 11,   /* fatal DNS error */
85         PS_BSMTP        = 12,   /* output batch could not be opened */
86         PS_MAXFETCH     = 13,   /* poll ended by fetch limit */
87
88         PS_NOTSUPPORTED = 14,   /* command not supported */
89
90         /* leave space for more codes */
91
92         PS_CONTINUE     = 128   /* more responses may follow */
93 } Pop3ErrorValue;
94
95 typedef enum {
96         RECV_TIME_NONE     = 0,
97         RECV_TIME_RECEIVED = 1,
98         RECV_TIME_KEEP     = 2
99 } RecvTime;
100
101 typedef enum {
102         POP3_PARTIAL_DLOAD_UNKN = 0,
103         POP3_PARTIAL_DLOAD_DLOAD= 1,
104         POP3_PARTIAL_DLOAD_DELE = 2
105 } PartialDownloadAction;
106
107 struct _Pop3MsgInfo
108 {
109         gint size;
110         gchar *uidl;
111         time_t recv_time;
112         guint received     : 1;
113         guint deleted      : 1;
114         guint partial_recv : 2;
115 };
116
117 struct _Pop3Session
118 {
119         Session session;
120
121         Pop3State state;
122         gchar *prev_folder;
123
124         PrefsAccount *ac_prefs;
125         gboolean pop_before_smtp;
126
127         gchar *greeting;
128         gchar *user;
129         gchar *pass;
130         gint count;
131         gint total_bytes;
132         gint cur_msg;
133         gint cur_total_num;
134         gint cur_total_bytes;
135         gint cur_total_recv_bytes;
136
137         Pop3MsgInfo *msg;
138
139         GHashTable *uidl_table;
140         GHashTable *partial_recv_table;
141         
142         gboolean new_msg_exist;
143         gboolean uidl_is_valid;
144
145         time_t current_time;
146
147         Pop3ErrorValue error_val;
148         gchar *error_msg;
149
150         gpointer data;
151
152         /* virtual method to drop message */
153         gint (*drop_message)    (Pop3Session    *session,
154                                  const gchar    *file,
155                                  gboolean        update_file);
156 };
157
158 #define POPBUFSIZE      512
159 #define IDLEN           128
160
161
162 Session *pop3_session_new       (PrefsAccount   *account);
163 void pop3_get_uidl_table        (PrefsAccount   *account, Pop3Session *session);
164 gint pop3_write_uidl_list       (Pop3Session    *session);
165 gint pop3_msg_in_uidl_list      (const gchar    *server, 
166                                  const gchar    *login, 
167                                  const gchar    *uidl);
168 int pop3_mark_for_download      (const gchar    *server, 
169                                  const gchar    *login, 
170                                  const gchar    *uidl, 
171                                  const gchar    *filename);
172 int pop3_mark_for_delete        (const gchar    *server, 
173                                  const gchar    *login, 
174                                  const gchar    *uidl, 
175                                  const gchar    *filename);
176
177 #endif /* __POP_H__ */