0738e947e39ff3ba1e80f4641c792853a52c6a96
[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 num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
159
160         long lowest_found;     /* smallest Message ID found;  */
161         long highest_found;    /* highest Message ID found;  */
162
163 } SharedMessageStatus;
164
165 int load_msg_ptrs(const char *servcmd,
166                   const char *filter,
167                   SharedMessageStatus *Stat, 
168                   load_msg_ptrs_detailheaders LH);
169
170 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
171                                            void **ViewSpecific, 
172                                            long oper, 
173                                            char *cmd, 
174                                            long len,
175                                            char *filter,
176                                            long flen);
177
178 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
179
180 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
181                                       void **ViewSpecific, 
182                                       message_summary* Msg, 
183                                       int is_new, 
184                                       int i);
185
186 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
187                                        void **ViewSpecific, 
188                                        long oper);
189 typedef int (*View_Cleanup_func)(void **ViewSpecific);
190
191 void RegisterReadLoopHandlerset(
192         /**
193          * RoomType: which View definition are you going to be called for
194          */
195         int RoomType,
196
197         /**
198          * GetParamsGetServerCall should do the following:
199          *  * allocate your private context structure
200          *  * evaluate your commandline arguments, put results to your private struct.
201          *  * fill cmd with the command to load the message pointer list:
202          *    * might depend on bstr/oper depending on your needs
203          *    * might stay empty if no list should loaded and LoadMsgFromServer 
204          *      is skipped.
205          *  * influence the behaviour by presetting values on SharedMessageStatus
206          */
207         GetParamsGetServerCall_func GetParamsGetServerCall,
208
209         /**
210          * PrintpageHeader prints the surrounding information like iconbar, header etc.
211          * by default, output_headers() is called.
212          *
213          */
214         PrintViewHeader_func PrintPageHeader,
215
216         /**
217          * PrintViewHeader is here to print informations infront of your messages.
218          * The message list is already loaded & sorted (if) so you can evaluate 
219          * its result on the SharedMessageStatus struct.
220          */
221         PrintViewHeader_func PrintViewHeader,
222
223         /**
224          * LH is the function, you specify if you want to load more than just message
225          * numbers from the server during the listing fetch operation.
226          */
227         load_msg_ptrs_detailheaders LH,
228
229         /**
230          * LoadMsgFromServer is called for every message in the message list:
231          *  * which is 
232          *    * after 'startmsg'  
233          *    * up to 'maxmsgs' after your 'startmsg'
234          *  * it should load and parse messages from citserer.
235          *  * depending on your needs you might want to print your message here...
236          *  * if cmd was empty, its skipped alltogether.
237          */
238         LoadMsgFromServer_func LoadMsgFromServer,
239
240         /**
241          * RenderView_or_Tail is called last; 
242          *  * if you used PrintViewHeader to print messages, you might want to print 
243          *    trailing information here
244          *  * if you just pre-loaded your messages, put your render code here.
245          */
246         RenderView_or_Tail_func RenderView_or_Tail,
247
248         /**
249          * ViewCleanup should just clear your private data so all your mem can go back to 
250          * VALgrindHALLA.
251          * it also should release the content for delivery via end_burst() or wDumpContent(1);
252          */
253         View_Cleanup_func ViewCleanup
254         );
255 /*
256 GetParamsGetServerCall
257
258 PrintViewHeader
259
260 LoadMsgFromServer
261
262 RenderView_or_Tail
263 */
264
265
266 int ParseMessageListHeaders_Detail(StrBuf *Line, 
267                                    const char **pos, 
268                                    message_summary *Msg, 
269                                    StrBuf *ConversionBuffer);
270
271
272
273 /**
274  * @brief function to register the availability to render a specific message
275  * @param HeaderName Mimetype we know howto display
276  * @param HdrNLen length...
277  * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
278  * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
279  */
280 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
281                           RenderMimeFunc MimeRenderer,
282                           int InlineRenderable,
283                           int Priority);