8113f675bb37b75fec8f5bfed9f57d550c69eded
[citadel.git] / citadel / modules / imap / serv_imap.h
1 #define GLOBAL_UIDVALIDITY_VALUE        1L
2
3
4 void imap_cleanup_function(void);
5 void imap_greeting(void);
6 void imap_command_loop(void);
7 int imap_grabroom(char *returned_roomname, const char *foldername, int zapped_ok);
8 void imap_free_transmitted_message(void);
9 int imap_do_expunge(void);
10 void imap_rescan_msgids(void);
11
12 /*
13  * FDELIM defines which character we want to use as a folder delimiter
14  * in room names.  Originally we used a forward slash, but that caused
15  * rooms with names like "Sent/Received Pages" to get delimited, so we
16  * changed it to a backslash.  This is completely irrelevant to how Citadel
17  * speaks to IMAP clients -- the delimiter used in the IMAP protocol is
18  * a vertical bar, which is illegal in Citadel room names anyway.
19  */
20
21 typedef void (*imap_handler)(int num_parms, ConstStr *Params);
22
23 typedef struct _imap_handler_hook {
24         imap_handler h;
25         int Flags;
26 } imap_handler_hook;
27
28 typedef struct __citimap_command {
29         StrBuf *CmdBuf;                 /* our current commandline; gets chopped into: */
30         ConstStr *Params;               /* Commandline tokens */
31         int num_parms;                  /* Number of Commandline tokens available */
32         int avail_parms;                /* Number of ConstStr args is big */
33         const imap_handler_hook *hh;
34 } citimap_command;
35
36
37 typedef struct __citimap {
38         StrBuf *Reply;
39         int authstate;
40         char authseq[SIZ];
41         int selected;                   /* set to 1 if in the SELECTED state */
42         int readonly;                   /* mailbox is open read only */
43         int num_msgs;                   /* Number of messages being mapped */
44         int num_alloc;                  /* Number of messages for which we've allocated space */
45         time_t last_mtime;              /* For checking whether the room was modified... */
46         long *msgids;
47         unsigned int *flags;
48
49         StrBuf *TransmittedMessage;     /* for APPEND command... */
50
51         citimap_command Cmd;            /* our current commandline */
52
53         /* Cache most recent RFC822 FETCH because client might load in pieces */
54         StrBuf *cached_rfc822;
55         long cached_rfc822_msgnum;
56         char cached_rfc822_withbody;    /* 1 = body cached; 0 = only headers cached */
57
58         /* Cache most recent BODY FETCH because client might load in pieces */
59         char *cached_body;
60         size_t cached_body_len;
61         char cached_bodypart[SIZ];
62         long cached_bodymsgnum;
63         char cached_body_withbody;      /* 1 = body cached; 0 = only headers cached */
64 } citimap;
65
66 /*
67  * values of 'authstate'
68  */
69 enum {
70         imap_as_normal,
71         imap_as_expecting_username,
72         imap_as_expecting_password,
73         imap_as_expecting_plainauth,
74         imap_as_expecting_multilineusername,
75         imap_as_expecting_multilinepassword
76 };
77
78 /* Flags for the above struct.  Note that some of these are for internal use,
79  * and are not to be reported to IMAP clients.
80  */
81 #define IMAP_ANSWERED           1       /* reportable and setable */
82 #define IMAP_FLAGGED            2       /* reportable and setable */
83 #define IMAP_DELETED            4       /* reportable and setable */
84 #define IMAP_DRAFT              8       /* reportable and setable */
85 #define IMAP_SEEN               16      /* reportable and setable */
86
87 #define IMAP_MASK_SETABLE       0x1f
88 #define IMAP_MASK_SYSTEM        0xe0
89
90 #define IMAP_SELECTED           32      /* neither reportable nor setable */
91 #define IMAP_RECENT             64      /* reportable but not setable */
92
93
94 /*
95  * Flags that may be returned by imap_roomname()
96  * (the lower eight bits will be the floor number)
97  */
98 #define IR_MAILBOX      0x0100          /* Mailbox                       */
99 #define IR_EXISTS       0x0200          /* Room exists (not implemented) */
100 #define IR_BABOON       0x0000          /* Just had to put this here :)  */
101
102 #define FDELIM '\\'
103
104
105 #define IMAP ((citimap *)CC->session_specific_data)
106
107 #define I_FLAG_NONE          (0)
108 #define I_FLAG_LOGGED_IN  (1<<0)
109 #define I_FLAG_SELECT     (1<<1)
110 /* RFC3501 says that we cannot output untagged data during these commands */
111 #define I_FLAG_UNTAGGED   (1<<2)
112
113 /*
114  * When loading arrays of message ID's into memory, increase the buffer to
115  * hold this many additional messages instead of calling realloc() each time.
116  */
117 #define REALLOC_INCREMENT 100
118
119
120 void registerImapCMD(const char *First, long FLen, 
121                      const char *Second, long SLen,
122                      imap_handler H,
123                      int Flags);
124
125 #define RegisterImapCMD(First, Second, H, Flags) \
126         registerImapCMD(HKEY(First), HKEY(Second), H, Flags)