3 * Copyright (c) 1996-2020 by the citadel.org team
5 * This program is open source software. You can redistribute it and/or
6 * modify it under the terms of the GNU General Public License, version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
16 extern CtxType CTX_MAILSUM;
17 extern CtxType CTX_MIME_ATACH;
18 extern HashList *MimeRenderHandler;
19 extern HashList *ReadLoopHandler;
20 typedef struct wc_mime_attachment wc_mime_attachment;
21 typedef void (*RenderMimeFunc)(StrBuf * Target, WCTemplputParams * TP, StrBuf * FoundCharset);
22 typedef struct _RenderMimeFuncStruct {
24 } RenderMimeFuncStruct;
26 struct wc_mime_attachment {
35 size_t length; /* length of the mimeattachment */
37 long lvalue; /* if we put a long... */
38 long msgnum; /* the message number on the citadel server derived from message_summary */
39 const RenderMimeFuncStruct *Renderer;
41 void DestroyMime(void *vMime);
43 #define MSGFLAG_READ (1<<0)
45 typedef struct _message_summary {
46 long msgnum; // the message number on the citadel server
48 time_t date; // its creation date
52 StrBuf *from; // display name of message author
53 StrBuf *to; // the recipient
54 StrBuf *subj; // title / subject
55 StrBuf *reply_inreplyto;
56 long reply_inreplyto_hash;
57 StrBuf *reply_references;
58 long reply_references_hash;
63 StrBuf *Rfca; // UPN or email address of message author
65 const StrBuf *PartNum;
66 HashList *Attachments; // list of attachments
67 HashList *Submessages;
68 HashList *AttachLinks;
71 int is_local; // nonzero if the message originated on the local system
72 wc_mime_attachment *MsgBody; // the MIME part of the message
75 void DestroyMessageSummary(void *vMsg);
77 /* some of these fields map to msgkeys[] in msgbase.c ... others don't */
79 /* I think these are supposed to align with fieldMnemonics in msg_renderers.c
80 * So if you change one you have to change the other.
81 * TODO: figure out who did this and beat them with a wet noodle.
83 typedef enum _eMessageField {
108 extern const char *fieldMnemonics[];
110 int GetFieldFromMnemonic(eMessageField * f, const char *c);
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);
115 static inline message_summary *GetMessagePtrAt(int n, HashList * Summ) {
123 GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
124 return (message_summary *) vMsg;
128 typedef void (*ExamineMsgHeaderFunc)(message_summary * Msg, StrBuf * HdrLine, StrBuf * FoundCharset);
129 void evaluate_mime_part(StrBuf * Target, WCTemplputParams * TP);
131 typedef enum _eCustomRoomRenderer {
132 eUseDefault = VIEW_JOURNAL + 100,
134 } eCustomRoomRenderer;
147 * @brief function to parse the | separated message headers list
148 * @param Line the raw line with your message data
149 * @param Msg put your parser results here...
150 * @param ConversionBuffer if you need some workbuffer, don't free me!
151 * @param ViewSpecific your view specific context data
152 * @returns 0: failure, trash this message. 1: all right, store it
154 typedef int (*load_msg_ptrs_detailheaders)(StrBuf * Line,
155 const char **pos, message_summary * Msg, StrBuf * ConversionBuffer, void **ViewSpecific);
157 typedef void (*readloop_servcmd)(char *buf, long bufsize);
159 typedef struct _readloopstruct {
161 readloop_servcmd cmd;
164 extern readloop_struct rlid[];
166 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
167 int read_message(StrBuf * Target,
168 const char *tmpl, long tmpllen,
169 long msgnum, const StrBuf * section, const StrBuf ** OutMime, WCTemplputParams * TP);
170 int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error);
175 typedef struct _SharedMessageStatus {
176 long load_seen; /* should read information be loaded */
177 long sortit; /* should we sort it using the standard sort API? */
178 long defaultsortorder; /* if we should sort it, which direction should be the default? */
180 long maxload; /* how many headers should we accept from the server? defaults to 10k */
181 long maxmsgs; /* how many message bodies do you want to load at most? */
183 long startmsg; /* which is the start message? */
184 long nummsgs; /* How many messages are available to your view? */
185 long numNewmsgs; /* if you load the seen-status, this is the count of them. */
186 long num_displayed; /* counted up for LoadMsgFromServer *//* TODO: unclear who should access this and why */
188 long lowest_found; /* smallest Message ID found; */
189 long highest_found; /* highest Message ID found; */
191 } SharedMessageStatus;
193 int load_msg_ptrs(const char *servcmd,
195 StrBuf * FoundCharset,
196 SharedMessageStatus * Stat,
198 load_msg_ptrs_detailheaders LH, StrBuf * FetchMessageList, eMessageField * MessageFieldList, long HeaderCount);
200 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus * Stat,
201 void **ViewSpecific, long oper, char *cmd, long len, char *filter, long flen);
203 typedef int (*PrintViewHeader_func)(SharedMessageStatus * Stat, void **ViewSpecific);
205 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus * Stat, void **ViewSpecific, message_summary * Msg, int is_new, int i);
207 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus * Stat, void **ViewSpecific, long oper);
208 typedef int (*View_Cleanup_func)(void **ViewSpecific);
210 void RegisterReadLoopHandlerset(
213 * RoomType: which View definition are you going to be called for
218 * GetParamsGetServerCall should do the following:
219 * * allocate your private context structure
220 * * evaluate your commandline arguments, put results to your private struct.
221 * * fill cmd with the command to load the message pointer list:
222 * * might depend on bstr/oper depending on your needs
223 * * might stay empty if no list should loaded and LoadMsgFromServer
225 * * influence the behaviour by presetting values on SharedMessageStatus
227 GetParamsGetServerCall_func GetParamsGetServerCall,
230 * PrintpageHeader prints the surrounding information like iconbar, header etc.
231 * by default, output_headers() is called.
234 PrintViewHeader_func PrintPageHeader,
237 * PrintViewHeader is here to print informations infront of your messages.
238 * The message list is already loaded & sorted (if) so you can evaluate
239 * its result on the SharedMessageStatus struct.
241 PrintViewHeader_func PrintViewHeader,
244 * LH is the function, you specify if you want to load more than just message
245 * numbers from the server during the listing fetch operation.
247 load_msg_ptrs_detailheaders LH,
250 * LoadMsgFromServer is called for every message in the message list:
253 * * up to 'maxmsgs' after your 'startmsg'
254 * * it should load and parse messages from citserer.
255 * * depending on your needs you might want to print your message here...
256 * * if cmd was empty, its skipped alltogether.
258 LoadMsgFromServer_func LoadMsgFromServer,
261 * RenderView_or_Tail is called last;
262 * * if you used PrintViewHeader to print messages, you might want to print
263 * trailing information here
264 * * if you just pre-loaded your messages, put your render code here.
266 RenderView_or_Tail_func RenderView_or_Tail,
269 * ViewCleanup should just clear your private data so all your mem can go back to
271 * it also should release the content for delivery via end_burst() or wDumpContent(1);
273 View_Cleanup_func ViewCleanup,
276 * brofwseListFields schould be a NULL-terminated list of message field mnemonics
277 * that will be the browse vector for the message header list.
279 const char **browseListFields);
282 GetParamsGetServerCall
292 int ParseMessageListHeaders_Detail(StrBuf * Line,
293 const char **pos, message_summary * Msg, StrBuf * ConversionBuffer, void **ViewSpecific);
296 * @brief function to register the availability to render a specific message
297 * @param HeaderName Mimetype we know howto display
298 * @param HdrNLen length...
299 * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
300 * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
302 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer, int InlineRenderable, int Priority);
306 * @brief fill the header parts of Msg with the headers loaded by MSG0
307 * @param Msg empty message struct, only preinitialized with the msgid
308 * @param FoundCharset buffer with the prefered charset of the headers
309 * @param buf linebuffer used to buffer citserver replies
311 int ReadOneMessageSummary(message_summary * Msg, StrBuf * FoundCharset, StrBuf * Buf);