3c0145b9a42213c8fdda6fd029c5e23d82c2103c
[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
13 extern CtxType CTX_MAILSUM;
14 extern CtxType CTX_MIME_ATACH;
15 extern HashList *MsgHeaderHandler;
16 extern HashList *MimeRenderHandler;
17 extern HashList *ReadLoopHandler;
18 typedef struct wc_mime_attachment wc_mime_attachment;
19 typedef void (*RenderMimeFunc)(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset);
20 typedef struct _RenderMimeFuncStruct {
21         RenderMimeFunc f;
22 } RenderMimeFuncStruct;
23
24 struct wc_mime_attachment {
25         int level;
26         StrBuf *Name;
27         StrBuf *FileName;
28         StrBuf *PartNum;
29         StrBuf *Disposition;
30         StrBuf *ContentType;
31         StrBuf *Charset;
32         StrBuf *Data;
33         size_t length;          /* length of the mimeattachment */
34         long size_known;
35         long lvalue;            /* if we put a long... */
36         long msgnum;            /* the message number on the citadel server derived from message_summary */
37         const RenderMimeFuncStruct *Renderer;
38 };
39 void DestroyMime(void *vMime);
40
41 #define MSGFLAG_READ (1<<0)
42
43 typedef struct _message_summary {
44         long msgnum;            /* the message number on the citadel server */
45         int Flags;
46
47         time_t date;            /* its creation date */
48         int nhdr;
49         int format_type;
50         StrBuf *euid;
51         StrBuf *from;           /* the author */
52         StrBuf *to;             /* the recipient */
53         StrBuf *subj;           /* the title / subject */
54         StrBuf *reply_inreplyto;
55         StrBuf *reply_references;
56         StrBuf *ReplyTo;
57         StrBuf *cccc;
58         StrBuf *hnod;
59         StrBuf *AllRcpt;
60         StrBuf *Room;
61         StrBuf *Rfca;
62         StrBuf *EnvTo;
63         StrBuf *OtherNode;
64         const StrBuf *PartNum;
65
66         HashList *Attachments;  /* list of attachments */
67         HashList *Submessages;
68         HashList *AttachLinks;
69
70         HashList *AllAttach;
71
72         int hasattachments;
73
74
75         /* The mime part of the message */
76         wc_mime_attachment *MsgBody;
77 } message_summary;
78 void DestroyMessageSummary(void *vMsg);
79
80
81
82 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
83 {
84         const char *Key;
85         long HKLen;
86         void *vMsg;
87
88         if (Summ == NULL)
89                 return NULL;
90         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
91         return (message_summary*) vMsg;
92 }
93
94 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
95
96 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
97
98
99 typedef enum _eCustomRoomRenderer {
100         eUseDefault = VIEW_JOURNAL + 100, 
101         eReadEUIDS
102 }eCustomRoomRenderer;
103
104 enum {
105         do_search,
106         headers,
107         readfwd,
108         readnew,
109         readold,
110         readgt,
111         readlt
112 };
113
114 /**
115  * @brief function to parse the | separated message headers list
116  * @param Line the raw line with your message data
117  * @param Msg put your parser results here...
118  * @param ConversionBuffer if you need some workbuffer, don't free me!
119  * @returns 0: failure, trash this message. 1: all right, store it
120  */
121 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line, 
122                                             const char **pos, 
123                                             message_summary *Msg, 
124                                             StrBuf *ConversionBuffer);
125
126 typedef void (*readloop_servcmd)(char *buf, long bufsize);
127
128 typedef struct _readloopstruct {
129         ConstStr name;
130         readloop_servcmd cmd;
131 } readloop_struct;
132
133 extern readloop_struct rlid[];
134
135 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
136 int read_message(StrBuf *Target, 
137                  const char *tmpl, long tmpllen, 
138                  long msgnum, 
139                  const StrBuf *section, 
140                  const StrBuf **OutMime);
141 int load_message(message_summary *Msg, 
142                  StrBuf *FoundCharset,
143                  StrBuf **Error);
144
145
146
147
148 typedef struct _SharedMessageStatus {
149         long load_seen;        /* should read information be loaded */
150         long sortit;           /* should we sort it using the standard sort API? */
151         long defaultsortorder; /* if we should sort it, which direction should be the default? */
152
153         long maxload;          /* how many headers should we accept from the server? defaults to 10k */
154         long maxmsgs;          /* how many message bodies do you want to load at most?*/
155
156         long startmsg;         /* which is the start message? */
157         long nummsgs;          /* How many messages are available to your view? */
158         long numNewmsgs;       /* if you load the seen-status, this is the count of them. */
159         long num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
160
161         long lowest_found;     /* smallest Message ID found;  */
162         long highest_found;    /* highest Message ID found;  */
163
164 } SharedMessageStatus;
165
166 int load_msg_ptrs(const char *servcmd,
167                   const char *filter,
168                   SharedMessageStatus *Stat, 
169                   load_msg_ptrs_detailheaders LH);
170
171 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
172                                            void **ViewSpecific, 
173                                            long oper, 
174                                            char *cmd, 
175                                            long len,
176                                            char *filter,
177                                            long flen);
178
179 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
180
181 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
182                                       void **ViewSpecific, 
183                                       message_summary* Msg, 
184                                       int is_new, 
185                                       int i);
186
187 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
188                                        void **ViewSpecific, 
189                                        long oper);
190 typedef int (*View_Cleanup_func)(void **ViewSpecific);
191
192 void RegisterReadLoopHandlerset(
193         /**
194          * RoomType: which View definition are you going to be called for
195          */
196         int RoomType,
197
198         /**
199          * GetParamsGetServerCall should do the following:
200          *  * allocate your private context structure
201          *  * evaluate your commandline arguments, put results to your private struct.
202          *  * fill cmd with the command to load the message pointer list:
203          *    * might depend on bstr/oper depending on your needs
204          *    * might stay empty if no list should loaded and LoadMsgFromServer 
205          *      is skipped.
206          *  * influence the behaviour by presetting values on SharedMessageStatus
207          */
208         GetParamsGetServerCall_func GetParamsGetServerCall,
209
210         /**
211          * PrintpageHeader prints the surrounding information like iconbar, header etc.
212          * by default, output_headers() is called.
213          *
214          */
215         PrintViewHeader_func PrintPageHeader,
216
217         /**
218          * PrintViewHeader is here to print informations infront of your messages.
219          * The message list is already loaded & sorted (if) so you can evaluate 
220          * its result on the SharedMessageStatus struct.
221          */
222         PrintViewHeader_func PrintViewHeader,
223
224         /**
225          * LH is the function, you specify if you want to load more than just message
226          * numbers from the server during the listing fetch operation.
227          */
228         load_msg_ptrs_detailheaders LH,
229
230         /**
231          * LoadMsgFromServer is called for every message in the message list:
232          *  * which is 
233          *    * after 'startmsg'  
234          *    * up to 'maxmsgs' after your 'startmsg'
235          *  * it should load and parse messages from citserer.
236          *  * depending on your needs you might want to print your message here...
237          *  * if cmd was empty, its skipped alltogether.
238          */
239         LoadMsgFromServer_func LoadMsgFromServer,
240
241         /**
242          * RenderView_or_Tail is called last; 
243          *  * if you used PrintViewHeader to print messages, you might want to print 
244          *    trailing information here
245          *  * if you just pre-loaded your messages, put your render code here.
246          */
247         RenderView_or_Tail_func RenderView_or_Tail,
248
249         /**
250          * ViewCleanup should just clear your private data so all your mem can go back to 
251          * VALgrindHALLA.
252          * it also should release the content for delivery via end_burst() or wDumpContent(1);
253          */
254         View_Cleanup_func ViewCleanup
255         );
256 /*
257 GetParamsGetServerCall
258
259 PrintViewHeader
260
261 LoadMsgFromServer
262
263 RenderView_or_Tail
264 */
265
266
267 int ParseMessageListHeaders_Detail(StrBuf *Line, 
268                                    const char **pos, 
269                                    message_summary *Msg, 
270                                    StrBuf *ConversionBuffer);
271
272
273
274 /**
275  * @brief function to register the availability to render a specific message
276  * @param HeaderName Mimetype we know howto display
277  * @param HdrNLen length...
278  * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
279  * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
280  */
281 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
282                           RenderMimeFunc MimeRenderer,
283                           int InlineRenderable,
284                           int Priority);