Straightn http client generation
[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 *display_recp;
76         char *bounce_to;
77         char *envelope_from;
78 };
79
80 #define RECPTYPES_MAGIC 0xfeeb
81
82 /*
83  * This is a list of "harvested" email addresses that we might want to
84  * stick into someone's address book.  But we defer this operaiton so
85  * it can be done asynchronously.
86  */
87 struct addresses_to_be_filed {
88         struct addresses_to_be_filed *next;
89         char *roomname;
90         char *collected_addresses;
91 };
92
93 extern struct addresses_to_be_filed *atbf;
94
95 int alias (char *name);
96 void cmd_msgs (char *cmdbuf);
97 void cmd_isme (char *cmdbuf);
98 void help_subst (char *strbuf, char *source, char *dest);
99 void do_help_subst (char *buffer);
100 void memfmout (char *mptr, const char *nl);
101 void output_mime_parts(char *);
102 void cmd_msg0 (char *cmdbuf);
103 void cmd_msg2 (char *cmdbuf);
104 void cmd_msg3 (char *cmdbuf);
105 void cmd_msg4 (char *cmdbuf);
106 void cmd_msgp (char *cmdbuf);
107 void cmd_opna (char *cmdbuf);
108 void cmd_dlat (char *cmdbuf);
109 long send_message (struct CtdlMessage *);
110 void loadtroom (void);
111 long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, const char *, int);
112 void quickie_message (const char *, const char *, char *, char *, const char *, int, const char *);
113 void cmd_ent0 (char *entargs);
114 void cmd_dele (char *delstr);
115 void cmd_move (char *args);
116 void GetMetaData(struct MetaData *, long);
117 void PutMetaData(struct MetaData *);
118 void AdjRefCount(long, int);
119 void TDAP_AdjRefCount(long, int);
120 int TDAP_ProcessAdjRefCountQueue(void);
121 void simple_listing(long, void *);
122 int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template);
123 typedef void (*ForEachMsgCallback)(long MsgNumber, void *UserData);
124 int CtdlForEachMessage(int mode,
125                         long ref,
126                         char *searchstring,
127                         char *content_type,
128                         struct CtdlMessage *compare,
129                         ForEachMsgCallback CallBack,
130                         void *userdata);
131 int CtdlDeleteMessages(char *, long *, int, char *);
132 void CtdlWriteObject(char *req_room,                    /* Room to stuff it in */
133                         char *content_type,             /* MIME type of this object */
134                         char *raw_message,              /* Data to be written */
135                         off_t raw_length,               /* Size of raw_message */
136                         struct ctdluser *is_mailbox,    /* Mailbox room? */
137                         int is_binary,                  /* Is encoding necessary? */
138                         int is_unique,                  /* Del others of this type? */
139                         unsigned int flags              /* Internal save flags */
140 );
141 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
142 void CtdlFreeMessage(struct CtdlMessage *msg);
143 void CtdlFreeMessageContents(struct CtdlMessage *msg);
144 void serialize_message(struct ser_ret *, struct CtdlMessage *);
145 void dump_message(struct CtdlMessage *msg, long Siz);
146 int is_valid_message(struct CtdlMessage *);
147 void ReplicationChecks(struct CtdlMessage *);
148 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
149                         int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj);
150 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
151 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, char *exist, int crlf, int *sock);
152 StrBuf *CtdlReadMessageBodyBuf(char *terminator,        /* token signalling EOT */
153                                long tlen,
154                                size_t maxlen,           /* maximum message length */
155                                char *exist,             /* if non-null, append to it;
156                                                            exist is ALWAYS freed  */
157                                int crlf,                /* CRLF newlines instead of LF */
158                                int *sock                /* socket handle or 0 for this session's client socket */
159         );
160
161 int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
162                   int mode,             /* how would you like that message? */
163                   int headers_only,     /* eschew the message body? */
164                   int do_proto,         /* do Citadel protocol responses? */
165                   int crlf,             /* 0=LF, 1=CRLF */
166                   char *section,                /* output a message/rfc822 section */
167                   int flags             /* should the bessage be exported clean? */
168 );
169
170 /* Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg() */
171 #define QP_EADDR        (1<<0)          /* quoted-printable encode email addresses */
172 #define CRLF            (1<<1)
173 #define ESC_DOT         (1<<2)          /* output a line containing only "." as ".." instead */
174 #define SUPPRESS_ENV_TO (1<<3)          /* suppress Envelope-to: header (warning: destructive!) */
175
176 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
177                            int mode,            /* how would you like that message? */
178                            int headers_only,    /* eschew the message body? */
179                            int do_proto,        /* do Citadel protocol responses? */
180                            int crlf,            /* 0=LF, 1=CRLF */
181                            int flags            /* should the bessage be exported clean? */
182 );
183 int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
184 int CtdlDoIHavePermissionToReadMessagesInThisRoom(void);
185
186 enum {
187         POST_LOGGED_IN,
188         POST_EXTERNAL,
189         CHECK_EXISTANCE,
190         POST_LMTP
191 };
192
193 int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, 
194         size_t n, 
195         const char* RemoteIdentifier,
196         int PostPublic,
197         int is_reply
198 );
199
200
201 /* values for which_set */
202 enum {
203         ctdlsetseen_seen,
204         ctdlsetseen_answered
205 };
206 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
207                  int target_setting, int which_set,
208                 struct ctdluser *which_user, struct ctdlroom *which_room);
209 void CtdlGetSeen(char *buf, int which_set);
210
211 struct recptypes *validate_recipients(const char *recipients,
212                                       const char *RemoteIdentifier, 
213                                       int Flags);
214
215 void free_recipients(struct recptypes *);
216
217 struct CtdlMessage *CtdlMakeMessage(
218         struct ctdluser *author,        /* author's user structure */
219         char *recipient,                /* NULL if it's not mail */
220         char *recp_cc,                  /* NULL if it's not mail */
221         char *room,                     /* room where it's going */
222         int type,                       /* see MES_ types in header file */
223         int format_type,                /* variformat, plain text, MIME... */
224         char *fake_name,                /* who we're masquerading as */
225         char *my_email,                 /* which of my email addresses to use (empty is ok) */
226         char *subject,                  /* Subject (optional) */
227         char *supplied_euid,            /* ...or NULL if this is irrelevant */
228         char *preformatted_text,        /* ...or NULL to read text from client */
229         char *references                /* Thread references */
230 );
231 int CtdlCheckInternetMailPermission(struct ctdluser *who);
232 int CtdlIsMe(char *addr, int addr_buf_len);
233
234 /*
235  * Use of aide_message is deprecated.
236  * It has been replaced with CtdlAideMessage.
237  * All parameters remain the same.
238 */
239 void aide_message(char *text, char *subject) __attribute__ ((deprecated));
240
241
242 /* 
243  * loading messages async via an FD: 
244  * add IO->ReadMsg = NewAsyncMsg(...)
245  * and then call CtdlReadMessageBodyAsync() from your linreader handler.
246  */
247
248 ReadAsyncMsg *NewAsyncMsg(const char *terminator,       /* token signalling EOT */
249                           long tlen,
250                           size_t expectlen,             /* if we expect a message, how long should it be? */
251                           size_t maxlen,                /* maximum message length */
252                           char *exist,                  /* if non-null, append to it;
253                                                            exist is ALWAYS freed  */
254                           long eLen,                    /* length of exist */
255                           int crlf                      /* CRLF newlines instead of LF */
256         );
257
258 eReadState CtdlReadMessageBodyAsync(AsyncIO *IO);
259 void DeleteAsyncMsg(ReadAsyncMsg **Msg);
260
261
262
263 #endif /* MSGBASE_H */