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