refactor naming of core message manipulation funcions
[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 };
23
24 /*
25  * Possible return codes from CtdlOutputMsg()
26  */
27 enum {
28         om_ok,
29         om_not_logged_in,
30         om_no_such_msg,
31         om_mime_error,
32         om_access_denied
33 };
34
35 /*
36  * Values of "headers_only" when calling message output routines
37  */
38 #define HEADERS_ALL     0       /* Headers and body */
39 #define HEADERS_ONLY    1       /* Headers only */
40 #define HEADERS_NONE    2       /* Body only */
41 #define HEADERS_FAST    3       /* Headers only with no MIME info */
42
43
44 struct ma_info {
45         int is_ma;              /* Set to 1 if we are using this stuff */
46         int freeze;             /* Freeze the replacement chain because we're
47                                  * digging through a subsection */
48         int did_print;          /* One alternative has been displayed */
49         char chosen_part[128];  /* Which part of a m/a did we choose? */
50         int chosen_pref;        /* Chosen part preference level (lower is better) */
51         int use_fo_hooks;       /* Use fixed output hooks */
52         int dont_decode;        /* should we call the decoder or not? */
53 };
54
55
56 struct repl {                   /* Info for replication checking */
57         char exclusive_id[SIZ];
58         time_t highest;
59 };
60
61
62 /* Data structure returned by validate_recipients() */
63 struct recptypes {
64         int recptypes_magic;
65         int num_local;
66         int num_internet;
67         int num_ignet;
68         int num_room;
69         int num_error;
70         char *errormsg;
71         char *recp_local;
72         char *recp_internet;
73         char *recp_ignet;
74         char *recp_room;
75         char *recp_orgroom;
76         char *display_recp;
77         char *bounce_to;
78         char *envelope_from;
79         char *sending_room;
80 };
81
82 #define RECPTYPES_MAGIC 0xfeeb
83
84 /*
85  * This is a list of "harvested" email addresses that we might want to
86  * stick into someone's address book.  But we defer this operaiton so
87  * it can be done asynchronously.
88  */
89 struct addresses_to_be_filed {
90         struct addresses_to_be_filed *next;
91         char *roomname;
92         char *collected_addresses;
93 };
94
95 extern struct addresses_to_be_filed *atbf;
96
97 int alias (char *name);
98 void cmd_msgs (char *cmdbuf);
99 void cmd_isme (char *cmdbuf);
100 void help_subst (char *strbuf, char *source, char *dest);
101 void do_help_subst (char *buffer);
102 void memfmout (char *mptr, const char *nl);
103 void output_mime_parts(char *);
104 void cmd_msg0 (char *cmdbuf);
105 void cmd_msg2 (char *cmdbuf);
106 void cmd_msg3 (char *cmdbuf);
107 void cmd_msg4 (char *cmdbuf);
108 void cmd_msgp (char *cmdbuf);
109 void cmd_opna (char *cmdbuf);
110 void cmd_dlat (char *cmdbuf);
111 long send_message (struct CtdlMessage *);
112 void loadtroom (void);
113 long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, const char *, int);
114
115 void quickie_message(const char *from,
116                      const char *fromaddr,
117                      const char *to,
118                      char *room,
119                      const char *text, 
120                      int format_type,
121                      const char *subject);
122
123 void flood_protect_quickie_message(const char *from,
124                                    const char *fromaddr,
125                                    const char *to,
126                                    char *room,
127                                    const char *text, 
128                                    int format_type,
129                                    const char *subject,
130                                    int nCriterions,
131                                    const char **CritStr,
132                                    long *CritStrLen,
133                                    long ccid,
134                                    long ioid,
135                                    time_t NOW);
136
137 void cmd_ent0 (char *entargs);
138 void cmd_dele (char *delstr);
139 void cmd_move (char *args);
140 void GetMetaData(struct MetaData *, long);
141 void PutMetaData(struct MetaData *);
142 void AdjRefCount(long, int);
143 void TDAP_AdjRefCount(long, int);
144 int TDAP_ProcessAdjRefCountQueue(void);
145 void simple_listing(long, void *);
146 int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template);
147 typedef void (*ForEachMsgCallback)(long MsgNumber, void *UserData);
148 int CtdlForEachMessage(int mode,
149                         long ref,
150                         char *searchstring,
151                         char *content_type,
152                         struct CtdlMessage *compare,
153                         ForEachMsgCallback CallBack,
154                         void *userdata);
155 int CtdlDeleteMessages(char *, long *, int, char *);
156 void CtdlWriteObject(char *req_room,                    /* Room to stuff it in */
157                         char *content_type,             /* MIME type of this object */
158                         char *raw_message,              /* Data to be written */
159                         off_t raw_length,               /* Size of raw_message */
160                         struct ctdluser *is_mailbox,    /* Mailbox room? */
161                         int is_binary,                  /* Is encoding necessary? */
162                         int is_unique,                  /* Del others of this type? */
163                         unsigned int flags              /* Internal save flags */
164 );
165 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
166 struct CtdlMessage * CM_Duplicate
167                        (struct CtdlMessage *OrgMsg);
168 int  CM_IsEmpty        (struct CtdlMessage *Msg, eMsgField which);
169 void CM_SetField       (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
170 void CM_SetFieldLONG   (struct CtdlMessage *Msg, eMsgField which, long lvalue);
171 void CM_CopyField      (struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy);
172 void CM_CutFieldAt     (struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen);
173 void CM_FlushField     (struct CtdlMessage *Msg, eMsgField which);
174 void CM_SetAsField     (struct CtdlMessage *Msg, eMsgField which, char **buf, long length);
175 void CM_SetAsFieldSB   (struct CtdlMessage *Msg, eMsgField which, StrBuf **buf);
176 void CM_GetAsField     (struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen);
177 void CM_PrependToField (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
178
179 void CM_Free           (struct CtdlMessage *msg);
180 void CM_FreeContents   (struct CtdlMessage *msg);
181 int  CM_IsValidMsg     (struct CtdlMessage *msg);
182
183 void serialize_message(struct ser_ret *, struct CtdlMessage *);
184 void ReplicationChecks(struct CtdlMessage *);
185 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
186                         int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj);
187 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
188 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf, int *sock);
189 StrBuf *CtdlReadMessageBodyBuf(char *terminator,        /* token signalling EOT */
190                                long tlen,
191                                size_t maxlen,           /* maximum message length */
192                                StrBuf *exist,           /* if non-null, append to it;
193                                                            exist is ALWAYS freed  */
194                                int crlf,                /* CRLF newlines instead of LF */
195                                int *sock                /* socket handle or 0 for this session's client socket */
196         );
197
198 int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
199                   int mode,             /* how would you like that message? */
200                   int headers_only,     /* eschew the message body? */
201                   int do_proto,         /* do Citadel protocol responses? */
202                   int crlf,             /* 0=LF, 1=CRLF */
203                   char *section,                /* output a message/rfc822 section */
204                   int flags,            /* should the bessage be exported clean? */
205                   char **Author,        /* if you want to know the author of the message... */
206                   char **Address        /* if you want to know the sender address of the message... */
207 );
208
209 /* Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg() */
210 #define QP_EADDR        (1<<0)          /* quoted-printable encode email addresses */
211 #define CRLF            (1<<1)
212 #define ESC_DOT         (1<<2)          /* output a line containing only "." as ".." instead */
213 #define SUPPRESS_ENV_TO (1<<3)          /* suppress Envelope-to: header (warning: destructive!) */
214
215 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
216                            int mode,            /* how would you like that message? */
217                            int headers_only,    /* eschew the message body? */
218                            int do_proto,        /* do Citadel protocol responses? */
219                            int crlf,            /* 0=LF, 1=CRLF */
220                            int flags            /* should the bessage be exported clean? */
221 );
222 int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
223 int CtdlDoIHavePermissionToReadMessagesInThisRoom(void);
224
225 enum {
226         POST_LOGGED_IN,
227         POST_EXTERNAL,
228         CHECK_EXISTANCE,
229         POST_LMTP
230 };
231
232 int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, 
233         size_t n, 
234         const char* RemoteIdentifier,
235         int PostPublic,
236         int is_reply
237 );
238
239
240 /* values for which_set */
241 enum {
242         ctdlsetseen_seen,
243         ctdlsetseen_answered
244 };
245 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
246                  int target_setting, int which_set,
247                 struct ctdluser *which_user, struct ctdlroom *which_room);
248 void CtdlGetSeen(char *buf, int which_set);
249
250 struct recptypes *validate_recipients(const char *recipients,
251                                       const char *RemoteIdentifier, 
252                                       int Flags);
253
254 void free_recipients(struct recptypes *);
255
256 struct CtdlMessage *CtdlMakeMessage(
257         struct ctdluser *author,        /* author's user structure */
258         char *recipient,                /* NULL if it's not mail */
259         char *recp_cc,                  /* NULL if it's not mail */
260         char *room,                     /* room where it's going */
261         int type,                       /* see MES_ types in header file */
262         int format_type,                /* variformat, plain text, MIME... */
263         char *fake_name,                /* who we're masquerading as */
264         char *my_email,                 /* which of my email addresses to use (empty is ok) */
265         char *subject,                  /* Subject (optional) */
266         char *supplied_euid,            /* ...or NULL if this is irrelevant */
267         char *preformatted_text,        /* ...or NULL to read text from client */
268         char *references                /* Thread references */
269 );
270 int CtdlCheckInternetMailPermission(struct ctdluser *who);
271 int CtdlIsMe(char *addr, int addr_buf_len);
272
273 /* 
274  * loading messages async via an FD: 
275  * add IO->ReadMsg = NewAsyncMsg(...)
276  * and then call CtdlReadMessageBodyAsync() from your linreader handler.
277  */
278
279 ReadAsyncMsg *NewAsyncMsg(const char *terminator,       /* token signalling EOT */
280                           long tlen,
281                           size_t expectlen,             /* if we expect a message, how long should it be? */
282                           size_t maxlen,                /* maximum message length */
283                           StrBuf *exist,                /* if non-null, append to it;
284                                                            exist is ALWAYS freed  */
285                           long eLen,                    /* length of exist */
286                           int crlf                      /* CRLF newlines instead of LF */
287         );
288
289 eReadState CtdlReadMessageBodyAsync(AsyncIO *IO);
290 void DeleteAsyncMsg(ReadAsyncMsg **Msg);
291
292 extern int MessageDebugEnabled;
293
294 #define MSGDBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (MessageDebugEnabled != 0))
295 #define CCCID CCC->cs_pid
296 #define MSG_syslog(LEVEL, FORMAT, ...)                  \
297         MSGDBGLOG(LEVEL) syslog(LEVEL,                  \
298                                 "CC[%d]MSG" FORMAT,     \
299                                 CCCID, __VA_ARGS__)
300
301 #define MSGM_syslog(LEVEL, FORMAT)                      \
302         MSGDBGLOG(LEVEL) syslog(LEVEL,                  \
303                                 "CC[%d]MSG" FORMAT,     \
304                                 CCCID)
305
306
307
308 #endif /* MSGBASE_H */