Mailing list header changes (fuck you Google)
[citadel.git] / webcit / messages.h
1 /*
2  * Copyright (c) 1996-2013 by the citadel.org team
3  *
4  * This program is open source software.  You can redistribute it and/or
5  * modify it under the terms of the GNU General Public License, version 3.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 #ifndef MESSAGES_H
13 #define MESSAGES_H
14
15 extern CtxType CTX_MAILSUM;
16 extern CtxType CTX_MIME_ATACH;
17 extern HashList *MimeRenderHandler;
18 extern HashList *ReadLoopHandler;
19 typedef struct wc_mime_attachment wc_mime_attachment;
20 typedef void (*RenderMimeFunc)(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset);
21 typedef struct _RenderMimeFuncStruct {
22         RenderMimeFunc f;
23 } RenderMimeFuncStruct;
24
25 struct wc_mime_attachment {
26         int level;
27         StrBuf *Name;
28         StrBuf *FileName;
29         StrBuf *PartNum;
30         StrBuf *Disposition;
31         StrBuf *ContentType;
32         StrBuf *Charset;
33         StrBuf *Data;
34         size_t length;          /* length of the mimeattachment */
35         long size_known;
36         long lvalue;            /* if we put a long... */
37         long msgnum;            /* the message number on the citadel server derived from message_summary */
38         const RenderMimeFuncStruct *Renderer;
39 };
40 void DestroyMime(void *vMime);
41
42 #define MSGFLAG_READ (1<<0)
43
44 typedef struct _message_summary {
45         long msgnum;            /* the message number on the citadel server */
46         int Flags;
47
48         time_t date;            /* its creation date */
49         int nhdr;
50         int format_type;
51         StrBuf *euid;
52         StrBuf *from;           /* the author */
53         StrBuf *to;             /* the recipient */
54         StrBuf *subj;           /* the title / subject */
55         StrBuf *reply_inreplyto;
56         long    reply_inreplyto_hash;
57         StrBuf *reply_references;
58         long    reply_references_hash;
59         StrBuf *ReplyTo;
60         StrBuf *cccc;
61         StrBuf *hnod;
62         StrBuf *AllRcpt;
63         StrBuf *Room;
64         StrBuf *Rfca;
65         StrBuf *EnvTo;
66         StrBuf *OtherNode;
67         const StrBuf *PartNum;
68
69         HashList *Attachments;  /* list of attachments */
70         HashList *Submessages;
71         HashList *AttachLinks;
72
73         HashList *AllAttach;
74
75         int hasattachments;
76
77
78         /* The mime part of the message */
79         wc_mime_attachment *MsgBody;
80 } message_summary;
81 void DestroyMessageSummary(void *vMsg);
82
83 /* Maps to msgkeys[] in msgbase.c: */
84
85 typedef enum _eMessageField {
86         eAuthor,
87         eXclusivID,
88         erFc822Addr,
89         eHumanNode,
90         emessageId,
91         eJournal,
92         eReplyTo,
93         eListID,
94         eMesageText,
95         eNodeName,
96         eOriginalRoom,
97         eMessagePath,
98         eRecipient,
99         eSpecialField,
100         eTimestamp,
101         eMsgSubject,
102         eenVelopeTo,
103         eWeferences,
104         eCarbonCopY,
105         eHeaderOnly,
106         eFormatType,
107         eMessagePart,
108         ePevious,
109         eSubFolder,
110         eLastHeader
111 }eMessageField;
112
113 extern const char* fieldMnemonics[];
114
115 int GetFieldFromMnemonic(eMessageField *f, const char* c);
116
117 int EvaluateMsgHdr(const char *HeaderName, long HdrNLen, message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
118 int EvaluateMsgHdrEnum(eMessageField f, message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
119
120
121
122 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
123 {
124         const char *Key;
125         long HKLen;
126         void *vMsg;
127
128         if (Summ == NULL)
129                 return NULL;
130         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
131         return (message_summary*) vMsg;
132 }
133
134 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
135
136 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
137
138
139 typedef enum _eCustomRoomRenderer {
140         eUseDefault = VIEW_JOURNAL + 100, 
141         eReadEUIDS
142 }eCustomRoomRenderer;
143
144 enum {
145         do_search,
146         headers,
147         readfwd,
148         readnew,
149         readold,
150         readgt,
151         readlt
152 };
153
154 /**
155  * @brief function to parse the | separated message headers list
156  * @param Line the raw line with your message data
157  * @param Msg put your parser results here...
158  * @param ConversionBuffer if you need some workbuffer, don't free me!
159  * @param ViewSpecific your view specific context data
160  * @returns 0: failure, trash this message. 1: all right, store it
161  */
162 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line, 
163                                             const char **pos, 
164                                             message_summary *Msg, 
165                                             StrBuf *ConversionBuffer,
166                                             void **ViewSpecific);
167
168 typedef void (*readloop_servcmd)(char *buf, long bufsize);
169
170 typedef struct _readloopstruct {
171         ConstStr name;
172         readloop_servcmd cmd;
173 } readloop_struct;
174
175 extern readloop_struct rlid[];
176
177 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
178 int read_message(StrBuf *Target, 
179                  const char *tmpl, long tmpllen, 
180                  long msgnum, 
181                  const StrBuf *section, 
182                  const StrBuf **OutMime,
183                  WCTemplputParams *TP);
184 int load_message(message_summary *Msg, 
185                  StrBuf *FoundCharset,
186                  StrBuf **Error);
187
188
189
190
191 typedef struct _SharedMessageStatus {
192         long load_seen;        /* should read information be loaded */
193         long sortit;           /* should we sort it using the standard sort API? */
194         long defaultsortorder; /* if we should sort it, which direction should be the default? */
195
196         long maxload;          /* how many headers should we accept from the server? defaults to 10k */
197         long maxmsgs;          /* how many message bodies do you want to load at most?*/
198
199         long startmsg;         /* which is the start message? */
200         long nummsgs;          /* How many messages are available to your view? */
201         long numNewmsgs;       /* if you load the seen-status, this is the count of them. */
202         long num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
203
204         long lowest_found;     /* smallest Message ID found;  */
205         long highest_found;    /* highest Message ID found;  */
206
207 } SharedMessageStatus;
208
209 int load_msg_ptrs(const char *servcmd,
210                   const char *filter,
211                   StrBuf *FoundCharset,
212                   SharedMessageStatus *Stat,
213                   void **ViewSpecific,
214                   load_msg_ptrs_detailheaders LH,
215                   StrBuf *FetchMessageList,
216                   eMessageField *MessageFieldList,
217                   long HeaderCount);
218
219 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
220                                            void **ViewSpecific, 
221                                            long oper, 
222                                            char *cmd, 
223                                            long len,
224                                            char *filter,
225                                            long flen);
226
227 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
228
229 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
230                                       void **ViewSpecific, 
231                                       message_summary* Msg, 
232                                       int is_new, 
233                                       int i);
234
235 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
236                                        void **ViewSpecific, 
237                                        long oper);
238 typedef int (*View_Cleanup_func)(void **ViewSpecific);
239
240 void RegisterReadLoopHandlerset(
241         /**
242          * RoomType: which View definition are you going to be called for
243          */
244         int RoomType,
245
246         /**
247          * GetParamsGetServerCall should do the following:
248          *  * allocate your private context structure
249          *  * evaluate your commandline arguments, put results to your private struct.
250          *  * fill cmd with the command to load the message pointer list:
251          *    * might depend on bstr/oper depending on your needs
252          *    * might stay empty if no list should loaded and LoadMsgFromServer 
253          *      is skipped.
254          *  * influence the behaviour by presetting values on SharedMessageStatus
255          */
256         GetParamsGetServerCall_func GetParamsGetServerCall,
257
258         /**
259          * PrintpageHeader prints the surrounding information like iconbar, header etc.
260          * by default, output_headers() is called.
261          *
262          */
263         PrintViewHeader_func PrintPageHeader,
264
265         /**
266          * PrintViewHeader is here to print informations infront of your messages.
267          * The message list is already loaded & sorted (if) so you can evaluate 
268          * its result on the SharedMessageStatus struct.
269          */
270         PrintViewHeader_func PrintViewHeader,
271
272         /**
273          * LH is the function, you specify if you want to load more than just message
274          * numbers from the server during the listing fetch operation.
275          */
276         load_msg_ptrs_detailheaders LH,
277
278         /**
279          * LoadMsgFromServer is called for every message in the message list:
280          *  * which is 
281          *    * after 'startmsg'  
282          *    * up to 'maxmsgs' after your 'startmsg'
283          *  * it should load and parse messages from citserer.
284          *  * depending on your needs you might want to print your message here...
285          *  * if cmd was empty, its skipped alltogether.
286          */
287         LoadMsgFromServer_func LoadMsgFromServer,
288
289         /**
290          * RenderView_or_Tail is called last; 
291          *  * if you used PrintViewHeader to print messages, you might want to print 
292          *    trailing information here
293          *  * if you just pre-loaded your messages, put your render code here.
294          */
295         RenderView_or_Tail_func RenderView_or_Tail,
296
297         /**
298          * ViewCleanup should just clear your private data so all your mem can go back to 
299          * VALgrindHALLA.
300          * it also should release the content for delivery via end_burst() or wDumpContent(1);
301          */
302         View_Cleanup_func ViewCleanup,
303         /**
304          * brofwseListFields schould be a NULL-terminated list of message field mnemonics
305          * that will be the browse vector for the message header list.
306          */
307         const char **browseListFields
308         );
309 /*
310 GetParamsGetServerCall
311
312 PrintViewHeader
313
314 LoadMsgFromServer
315
316 RenderView_or_Tail
317 */
318
319
320 int ParseMessageListHeaders_Detail(StrBuf *Line, 
321                                    const char **pos, 
322                                    message_summary *Msg, 
323                                    StrBuf *ConversionBuffer,
324                                    void **ViewSpecific);
325
326 /**
327  * @brief function to register the availability to render a specific message
328  * @param HeaderName Mimetype we know howto display
329  * @param HdrNLen length...
330  * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
331  * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
332  */
333 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
334                           RenderMimeFunc MimeRenderer,
335                           int InlineRenderable,
336                           int Priority);
337
338
339 /**
340  * @brief fill the header parts of Msg with the headers loaded by MSG0
341  * @param Msg empty message struct, only preinitialized with the msgid
342  * @param FoundCharset buffer with the prefered charset of the headers
343  * @param buf linebuffer used to buffer citserver replies
344  */
345 int ReadOneMessageSummary(message_summary *Msg, StrBuf *FoundCharset, StrBuf *Buf);
346
347 #endif