aboutsummaryrefslogtreecommitdiff
path: root/libsylph/pop.h
blob: b15f8ead8d8a217add689390e098e297ac1a28cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * LibSylph -- E-Mail client library
 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef __POP_H__
#define __POP_H__

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <glib.h>
#include <time.h>

#include "session.h"
#include "prefs_account.h"

typedef struct _Pop3MsgInfo	Pop3MsgInfo;
typedef struct _Pop3Session	Pop3Session;

#define POP3_SESSION(obj)	((Pop3Session *)obj)

typedef enum {
	POP3_READY,
	POP3_GREETING,
	POP3_STLS,
	POP3_GETAUTH_USER,
	POP3_GETAUTH_PASS,
	POP3_GETAUTH_APOP,
	POP3_GETRANGE_STAT,
	POP3_GETRANGE_LAST,
	POP3_GETRANGE_UIDL,
	POP3_GETRANGE_UIDL_RECV,
	POP3_GETSIZE_LIST,
	POP3_GETSIZE_LIST_RECV,
	POP3_RETR,
	POP3_RETR_RECV,
	POP3_DELETE,
	POP3_LOGOUT,
	POP3_DONE,
	POP3_ERROR,

	N_POP3_STATE
} Pop3State;

typedef enum {
	PS_SUCCESS	= 0,	/* command successful */
	PS_NOMAIL	= 1,	/* no mail available */
	PS_SOCKET	= 2,	/* socket I/O woes */
	PS_AUTHFAIL	= 3,	/* user authorization failed */
	PS_PROTOCOL	= 4,	/* protocol violation */
	PS_SYNTAX	= 5,	/* command-line syntax error */
	PS_IOERR	= 6,	/* file I/O error */
	PS_ERROR	= 7,	/* protocol error */
	PS_EXCLUDE	= 8,	/* client-side exclusion error */
	PS_LOCKBUSY	= 9,	/* server responded lock busy */
	PS_SMTP		= 10,	/* SMTP error */
	PS_DNS		= 11,	/* fatal DNS error */
	PS_BSMTP	= 12,	/* output batch could not be opened */
	PS_MAXFETCH	= 13,	/* poll ended by fetch limit */

	PS_NOTSUPPORTED	= 14,	/* command not supported */

	/* leave space for more codes */

	PS_CONTINUE	= 128	/* more responses may follow */
} Pop3ErrorValue;

typedef enum {
	RECV_TIME_NONE     = 0,
	RECV_TIME_RECEIVED = 1,
	RECV_TIME_KEEP     = 2,
	RECV_TIME_DELETE   = 3
} RecvTime;

typedef enum {
	DROP_OK = 0,
	DROP_DONT_RECEIVE = 1,
	DROP_DELETE = 2,
	DROP_ERROR = -1
} Pop3DropValue;

struct _Pop3MsgInfo
{
	gint size;
	gchar *uidl;
	time_t recv_time;
	guint received : 1;
	guint deleted  : 1;
};

struct _Pop3Session
{
	Session session;

	Pop3State state;

	PrefsAccount *ac_prefs;

	gchar *greeting;
	gchar *user;
	gchar *pass;
	gint count;
	gint64 total_bytes;
	gint cur_msg;
	gint cur_total_num;
	gint64 cur_total_bytes;
	gint64 cur_total_recv_bytes;

	Pop3MsgInfo *msg;

	GHashTable *uidl_table;

	gboolean new_msg_exist;
	gboolean uidl_is_valid;

	time_t current_time;

	Pop3ErrorValue error_val;
	gchar *error_msg;

	gpointer data;

	/* virtual method to drop message */
	gint (*drop_message)	(Pop3Session	*session,
				 const gchar	*file);
};

#define POPBUFSIZE	512
/* #define IDLEN	128 */
#define IDLEN		POPBUFSIZE

Session *pop3_session_new	(PrefsAccount	*account);
GHashTable *pop3_get_uidl_table	(PrefsAccount	*account);
gint pop3_write_uidl_list	(Pop3Session	*session);

#endif /* __POP_H__ */