lib-network
[apps/madmutt.git] / pop / pop.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 2000-2003 Vsevolod Volkov <vvv@mutt.org.ua>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #ifndef _POP_H
11 #define _POP_H 1
12
13 #include <lib-ui/curses.h>
14
15 #include "mx.h"
16 #include <lib-network/mutt_socket.h>
17
18 #define POP_PORT 110
19 #define POP_SSL_PORT 995
20
21 /* number of entries in the hash table */
22 #define POP_CACHE_LEN 10
23
24 /* maximal length of the server response (RFC1939) */
25 #define POP_CMD_RESPONSE 512
26
27 enum {
28   /* Status */
29   POP_NONE = 0,
30   POP_CONNECTED,
31   POP_DISCONNECTED,
32   POP_BYE
33 };
34
35 typedef enum {
36   POP_A_SUCCESS = 0,
37   POP_A_SOCKET,
38   POP_A_FAILURE,
39   POP_A_UNAVAIL
40 } pop_auth_res_t;
41
42 typedef struct {
43   unsigned int index;
44   char *path;
45 } POP_CACHE;
46
47 typedef enum pop_query_status_e {
48   PFD_FUNCT_ERROR = -3, /* pop_fetch_data uses pop_query_status and this return value */
49   PQ_ERR = -2,
50   PQ_NOT_CONNECTED = -1,
51   PQ_OK = 0
52 } pop_query_status;
53
54 typedef enum cmd_status_e {
55   CMD_NOT_AVAILABLE = 0,
56   CMD_AVAILABLE,
57   CMD_UNKNOWN /* unknown whether it is available or not */
58 } cmd_status;
59
60 typedef struct {
61   CONNECTION *conn;
62   unsigned int status:2;
63   unsigned int capabilities:1;
64   unsigned int use_stls:2;
65   cmd_status cmd_capa;      /* optional command CAPA */
66   cmd_status cmd_stls;      /* optional command STLS */
67   cmd_status cmd_user;      /* optional command USER */
68   cmd_status cmd_uidl;      /* optional command UIDL */
69   cmd_status cmd_top;       /* optional command TOP */
70   unsigned int resp_codes:1;    /* server supports extended response codes */
71   unsigned int expire:1;        /* expire is greater than 0 */
72   unsigned int clear_cache:1;
73   size_t size;
74   time_t check_time;
75   time_t login_delay;           /* minimal login delay  capability */
76   char *auth_list;              /* list of auth mechanisms */
77   char *timestamp;
78   char err_msg[POP_CMD_RESPONSE];
79   POP_CACHE cache[POP_CACHE_LEN];
80 } POP_DATA;
81
82 typedef struct {
83   /* do authentication, using named method or any available if method is NULL */
84   pop_auth_res_t (*authenticate) (POP_DATA *, const char *);
85   /* name of authentication method supported, NULL means variable. If this
86    * is not null, authenticate may ignore the second parameter. */
87   const char *method;
88 } pop_auth_t;
89
90 /* pop_auth.c */
91 int pop_authenticate (POP_DATA *);
92 void pop_apop_timestamp (POP_DATA *, char *);
93
94 /* pop_lib.c */
95 #define pop_query(A,B,C) pop_query_d(A,B,C,NULL)
96 int pop_parse_path (const char *, ACCOUNT *);
97 int pop_connect (POP_DATA *);
98 pop_query_status pop_open_connection (POP_DATA *);
99 pop_query_status pop_query_d (POP_DATA *, char *, size_t, const char *);
100 pop_query_status pop_fetch_data (POP_DATA *, const char *, progress_t*,
101                                  int (*funct) (char *, void *), void *);
102 pop_query_status pop_reconnect (CONTEXT *);
103 void pop_logout (CONTEXT *);
104 void pop_error (POP_DATA *, char *);
105
106 /* pop.c */
107 int pop_check_mailbox (CONTEXT *, int *, int);
108 int pop_open_mailbox (CONTEXT *);
109 pop_query_status pop_sync_mailbox (CONTEXT *, int, int *);
110 int pop_fetch_message (MESSAGE *, CONTEXT *, int);
111 void pop_close_mailbox (CONTEXT *);
112 void pop_fetch_mail (void);
113
114 #endif