bdd175991dfc0b159e667bf4edb5019c9ba7e0a6
[citadel.git] / citadel / msgbase.h
1
2 #ifndef MSGBASE_H
3 #define MSGBASE_H
4
5 #include "event_client.h"
6 enum {
7         MSGS_ALL,
8         MSGS_OLD,
9         MSGS_NEW,
10         MSGS_FIRST,
11         MSGS_LAST,
12         MSGS_GT,
13         MSGS_EQ,
14         MSGS_SEARCH,
15         MSGS_LT
16 };
17
18 enum {
19         MSG_HDRS_BRIEF = 0,
20         MSG_HDRS_ALL = 1,
21         MSG_HDRS_EUID = 4,
22         MSG_HDRS_BRIEFFILTER = 8,
23         MSG_HDRS_THREADS = 9
24 };
25
26 /*
27  * Possible return codes from CtdlOutputMsg()
28  */
29 enum {
30         om_ok,
31         om_not_logged_in,
32         om_no_such_msg,
33         om_mime_error,
34         om_access_denied
35 };
36
37 /*
38  * Values of "headers_only" when calling message output routines
39  */
40 #define HEADERS_ALL     0       /* Headers and body */
41 #define HEADERS_ONLY    1       /* Headers only */
42 #define HEADERS_NONE    2       /* Body only */
43 #define HEADERS_FAST    3       /* Headers only with no MIME info */
44
45
46 struct ma_info {
47         int is_ma;              /* Set to 1 if we are using this stuff */
48         int freeze;             /* Freeze the replacement chain because we're
49                                  * digging through a subsection */
50         int did_print;          /* One alternative has been displayed */
51         char chosen_part[128];  /* Which part of a m/a did we choose? */
52         int chosen_pref;        /* Chosen part preference level (lower is better) */
53         int use_fo_hooks;       /* Use fixed output hooks */
54         int dont_decode;        /* should we call the decoder or not? */
55 };
56
57
58 struct repl {                   /* Info for replication checking */
59         char exclusive_id[SIZ];
60         time_t highest;
61 };
62
63
64
65 /*
66  * This is a list of "harvested" email addresses that we might want to
67  * stick into someone's address book.  But we defer this operaiton so
68  * it can be done asynchronously.
69  */
70 struct addresses_to_be_filed {
71         struct addresses_to_be_filed *next;
72         char *roomname;
73         char *collected_addresses;
74 };
75
76 extern struct addresses_to_be_filed *atbf;
77
78 int GetFieldFromMnemonic(eMsgField *f, const char* c);
79
80
81 void memfmout (char *mptr, const char *nl);
82 void output_mime_parts(char *);
83 long send_message (struct CtdlMessage *);
84 void loadtroom (void);
85 long CtdlSubmitMsg(struct CtdlMessage *, recptypes *, const char *, int);
86
87 long quickie_message(const char *from, const char *fromaddr, const char *to, char *room, const char *text, int format_type, const char *subject);
88
89 void flood_protect_quickie_message(const char *from,
90                                    const char *fromaddr,
91                                    const char *to,
92                                    char *room,
93                                    const char *text, 
94                                    int format_type,
95                                    const char *subject,
96                                    int nCriterions,
97                                    const char **CritStr,
98                                    const long *CritStrLen,
99                                    long ccid,
100                                    long ioid,
101                                    time_t NOW);
102
103 void GetMetaData(struct MetaData *, long);
104 void PutMetaData(struct MetaData *);
105 void AdjRefCount(long, int);
106 void TDAP_AdjRefCount(long, int);
107 int TDAP_ProcessAdjRefCountQueue(void);
108 void simple_listing(long, void *);
109 int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template);
110 typedef void (*ForEachMsgCallback)(long MsgNumber, void *UserData);
111 int CtdlForEachMessage(int mode,
112                         long ref,
113                         char *searchstring,
114                         char *content_type,
115                         struct CtdlMessage *compare,
116                         ForEachMsgCallback CallBack,
117                         void *userdata);
118 int CtdlDeleteMessages(const char *, long *, int, char *);
119 void CtdlWriteObject(char *req_room,                    /* Room to stuff it in */
120                         char *content_type,             /* MIME type of this object */
121                         char *raw_message,              /* Data to be written */
122                         off_t raw_length,               /* Size of raw_message */
123                         struct ctdluser *is_mailbox,    /* Mailbox room? */
124                         int is_binary,                  /* Is encoding necessary? */
125                         int is_unique,                  /* Del others of this type? */
126                         unsigned int flags              /* Internal save flags */
127 );
128 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hooks);
129 struct CtdlMessage * CM_Duplicate
130                        (struct CtdlMessage *OrgMsg);
131 int  CM_IsEmpty        (struct CtdlMessage *Msg, eMsgField which);
132 void CM_SetField       (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
133 void CM_SetFieldLONG   (struct CtdlMessage *Msg, eMsgField which, long lvalue);
134 void CM_CopyField      (struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy);
135 void CM_CutFieldAt     (struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen);
136 void CM_FlushField     (struct CtdlMessage *Msg, eMsgField which);
137 void CM_Flush          (struct CtdlMessage *Msg);
138 void CM_SetAsField     (struct CtdlMessage *Msg, eMsgField which, char **buf, long length);
139 void CM_SetAsFieldSB   (struct CtdlMessage *Msg, eMsgField which, StrBuf **buf);
140 void CM_GetAsField     (struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen);
141 void CM_PrependToField (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
142
143 void CM_Free           (struct CtdlMessage *msg);
144 void CM_FreeContents   (struct CtdlMessage *msg);
145 int  CM_IsValidMsg     (struct CtdlMessage *msg);
146
147 #define CM_KEY(Message, Which) Message->cm_fields[Which], Message->cm_lengths[Which]
148 #define CM_RANGE(Message, Which) Message->cm_fields[Which], \
149                 Message->cm_fields[Which] + Message->cm_lengths[Which]
150
151 void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *);
152 struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
153 void ReplicationChecks(struct CtdlMessage *);
154 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
155                               int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj);
156 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
157 long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply);
158 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf, int *sock);
159 StrBuf *CtdlReadMessageBodyBuf(char *terminator,        /* token signalling EOT */
160                                long tlen,
161                                size_t maxlen,           /* maximum message length */
162                                StrBuf *exist,           /* if non-null, append to it;
163                                                            exist is ALWAYS freed  */
164                                int crlf,                /* CRLF newlines instead of LF */
165                                int *sock                /* socket handle or 0 for this session's client socket */
166         );
167
168 int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
169                 int mode,               /* how would you like that message? */
170                 int headers_only,       /* eschew the message body? */
171                 int do_proto,           /* do Citadel protocol responses? */
172                 int crlf,               /* 0=LF, 1=CRLF */
173                 char *section,          /* output a message/rfc822 section */
174                 int flags,              /* should the bessage be exported clean? */
175                 char **Author,          /* if you want to know the author of the message... */
176                 char **Address,         /* if you want to know the sender address of the message... */
177                 char **MessageID        /* if you want to know the Message-ID of the message... */
178 );
179
180 /* Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg() */
181 #define QP_EADDR        (1<<0)          /* quoted-printable encode email addresses */
182 #define CRLF            (1<<1)
183 #define ESC_DOT         (1<<2)          /* output a line containing only "." as ".." instead */
184 #define SUPPRESS_ENV_TO (1<<3)          /* suppress Envelope-to: header (warning: destructive!) */
185
186 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
187                            int mode,            /* how would you like that message? */
188                            int headers_only,    /* eschew the message body? */
189                            int do_proto,        /* do Citadel protocol responses? */
190                            int crlf,            /* 0=LF, 1=CRLF */
191                            int flags            /* should the bessage be exported clean? */
192 );
193
194
195 /* values for which_set */
196 enum {
197         ctdlsetseen_seen,
198         ctdlsetseen_answered
199 };
200 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
201                  int target_setting, int which_set,
202                 struct ctdluser *which_user, struct ctdlroom *which_room);
203 void CtdlGetSeen(char *buf, int which_set);
204
205
206 struct CtdlMessage *CtdlMakeMessage(
207         struct ctdluser *author,        /* author's user structure */
208         char *recipient,                /* NULL if it's not mail */
209         char *recp_cc,                  /* NULL if it's not mail */
210         char *room,                     /* room where it's going */
211         int type,                       /* see MES_ types in header file */
212         int format_type,                /* variformat, plain text, MIME... */
213         char *fake_name,                /* who we're masquerading as */
214         char *my_email,                 /* which of my email addresses to use (empty is ok) */
215         char *subject,                  /* Subject (optional) */
216         char *supplied_euid,            /* ...or NULL if this is irrelevant */
217         char *preformatted_text,        /* ...or NULL to read text from client */
218         char *references                /* Thread references */
219 );
220
221 struct CtdlMessage *CtdlMakeMessageLen(
222         struct ctdluser *author,        /* author's user structure */
223         char *recipient,                /* NULL if it's not mail */
224         long rcplen,
225         char *recp_cc,                  /* NULL if it's not mail */
226         long cclen,
227         char *room,                     /* room where it's going */
228         long roomlen,
229         int type,                       /* see MES_ types in header file */
230         int format_type,                /* variformat, plain text, MIME... */
231         char *fake_name,                /* who we're masquerading as */
232         long fnlen,
233         char *my_email,                 /* which of my email addresses to use (empty is ok) */
234         long myelen,
235         char *subject,                  /* Subject (optional) */
236         long subjlen,
237         char *supplied_euid,            /* ...or NULL if this is irrelevant */
238         long euidlen,
239         char *preformatted_text,        /* ...or NULL to read text from client */
240         long textlen,
241         char *references,               /* Thread references */
242         long reflen);
243
244 /* 
245  * loading messages async via an FD: 
246  * add IO->ReadMsg = NewAsyncMsg(...)
247  * and then call CtdlReadMessageBodyAsync() from your linreader handler.
248  */
249
250 ReadAsyncMsg *NewAsyncMsg(const char *terminator,       /* token signalling EOT */
251                           long tlen,
252                           size_t expectlen,             /* if we expect a message, how long should it be? */
253                           size_t maxlen,                /* maximum message length */
254                           StrBuf *exist,                /* if non-null, append to it;
255                                                            exist is ALWAYS freed  */
256                           long eLen,                    /* length of exist */
257                           int crlf                      /* CRLF newlines instead of LF */
258         );
259
260 eReadState CtdlReadMessageBodyAsync(AsyncIO *IO);
261 void DeleteAsyncMsg(ReadAsyncMsg **Msg);
262
263
264
265
266
267 #endif /* MSGBASE_H */