2 * Copyright (c) 1996-2013 by the citadel.org team
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.
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.
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 {
23 } RenderMimeFuncStruct;
25 struct wc_mime_attachment {
34 size_t length; /* length of the mimeattachment */
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;
40 void DestroyMime(void *vMime);
42 #define MSGFLAG_READ (1<<0)
44 typedef struct _message_summary {
45 long msgnum; /* the message number on the citadel server */
48 time_t date; /* its creation date */
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;
67 const StrBuf *PartNum;
69 HashList *Attachments; /* list of attachments */
70 HashList *Submessages;
71 HashList *AttachLinks;
78 /* The mime part of the message */
79 wc_mime_attachment *MsgBody;
81 void DestroyMessageSummary(void *vMsg);
83 /* Maps to msgkeys[] in msgbase.c: */
85 typedef enum _eMessageField {
113 extern const char* fieldMnemonics[];
115 int GetFieldFromMnemonic(eMessageField *f, const char* c);
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);
122 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
130 GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
131 return (message_summary*) vMsg;
134 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
136 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
139 typedef enum _eCustomRoomRenderer {
140 eUseDefault = VIEW_JOURNAL + 100,
142 }eCustomRoomRenderer;
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
162 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line,
164 message_summary *Msg,
165 StrBuf *ConversionBuffer,
166 void **ViewSpecific);
168 typedef void (*readloop_servcmd)(char *buf, long bufsize);
170 typedef struct _readloopstruct {
172 readloop_servcmd cmd;
175 extern readloop_struct rlid[];
177 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
178 int read_message(StrBuf *Target,
179 const char *tmpl, long tmpllen,
181 const StrBuf *section,
182 const StrBuf **OutMime,
183 WCTemplputParams *TP);
184 int load_message(message_summary *Msg,
185 StrBuf *FoundCharset,
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? */
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?*/
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 */
204 long lowest_found; /* smallest Message ID found; */
205 long highest_found; /* highest Message ID found; */
207 } SharedMessageStatus;
209 int load_msg_ptrs(const char *servcmd,
211 StrBuf *FoundCharset,
212 SharedMessageStatus *Stat,
214 load_msg_ptrs_detailheaders LH,
215 StrBuf *FetchMessageList,
216 eMessageField *MessageFieldList,
219 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat,
227 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
229 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat,
231 message_summary* Msg,
235 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat,
238 typedef int (*View_Cleanup_func)(void **ViewSpecific);
240 void RegisterReadLoopHandlerset(
242 * RoomType: which View definition are you going to be called for
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
254 * * influence the behaviour by presetting values on SharedMessageStatus
256 GetParamsGetServerCall_func GetParamsGetServerCall,
259 * PrintpageHeader prints the surrounding information like iconbar, header etc.
260 * by default, output_headers() is called.
263 PrintViewHeader_func PrintPageHeader,
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.
270 PrintViewHeader_func PrintViewHeader,
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.
276 load_msg_ptrs_detailheaders LH,
279 * LoadMsgFromServer is called for every message in the message list:
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.
287 LoadMsgFromServer_func LoadMsgFromServer,
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.
295 RenderView_or_Tail_func RenderView_or_Tail,
298 * ViewCleanup should just clear your private data so all your mem can go back to
300 * it also should release the content for delivery via end_burst() or wDumpContent(1);
302 View_Cleanup_func ViewCleanup,
304 * brofwseListFields schould be a NULL-terminated list of message field mnemonics
305 * that will be the browse vector for the message header list.
307 const char **browseListFields
310 GetParamsGetServerCall
320 int ParseMessageListHeaders_Detail(StrBuf *Line,
322 message_summary *Msg,
323 StrBuf *ConversionBuffer,
324 void **ViewSpecific);
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)
333 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
334 RenderMimeFunc MimeRenderer,
335 int InlineRenderable,
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
345 int ReadOneMessageSummary(message_summary *Msg, StrBuf *FoundCharset, StrBuf *Buf);