indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / messages.h
1
2 /*
3  * Copyright (c) 1996-2020 by the citadel.org team
4  *
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.
7  *
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.
12  */
13 #ifndef MESSAGES_H
14 #define MESSAGES_H
15
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 {
23         RenderMimeFunc f;
24 } RenderMimeFuncStruct;
25
26 struct wc_mime_attachment {
27         int level;
28         StrBuf *Name;
29         StrBuf *FileName;
30         StrBuf *PartNum;
31         StrBuf *Disposition;
32         StrBuf *ContentType;
33         StrBuf *Charset;
34         StrBuf *Data;
35         size_t length;          /* length of the mimeattachment */
36         long size_known;
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;
40 };
41 void DestroyMime(void *vMime);
42
43 #define MSGFLAG_READ (1<<0)
44
45 typedef struct _message_summary {
46         long msgnum;            // the message number on the citadel server
47         int Flags;
48         time_t date;            // its creation date
49         int nhdr;
50         int format_type;
51         StrBuf *euid;
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;
59         StrBuf *ReplyTo;
60         StrBuf *cccc;
61         StrBuf *AllRcpt;
62         StrBuf *Room;
63         StrBuf *Rfca;           // UPN or email address of message author
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         int is_local;           // nonzero if the message originated on the local system
72         wc_mime_attachment *MsgBody;    // the MIME part of the message
73 } message_summary;
74
75 void DestroyMessageSummary(void *vMsg);
76
77 /* some of these fields map to msgkeys[] in msgbase.c ... others don't */
78
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.
82  */
83 typedef enum _eMessageField {
84         eAuthor,
85         eXclusivID,
86         erFc822Addr,
87         emessageId,
88         eJournal,
89         eReplyTo,
90         eListID,
91         eMesageText,
92         eIsLocal,
93         eMessagePath,
94         eRecipient,
95         eSpecialField,
96         eTimestamp,
97         eMsgSubject,
98         eenVelopeTo,
99         eWeferences,
100         eCarbonCopY,
101         eHeaderOnly,
102         eFormatType,
103         eMessagePart,
104         eSubFolder,
105         eLastHeader
106 } eMessageField;
107
108 extern const char *fieldMnemonics[];
109
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);
113
114
115 static inline message_summary *GetMessagePtrAt(int n, HashList * Summ) {
116         const char *Key;
117         long HKLen;
118         void *vMsg;
119
120         if (Summ == NULL) {
121                 return NULL;
122         }
123         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
124         return (message_summary *) vMsg;
125 }
126
127
128 typedef void (*ExamineMsgHeaderFunc)(message_summary * Msg, StrBuf * HdrLine, StrBuf * FoundCharset);
129 void evaluate_mime_part(StrBuf * Target, WCTemplputParams * TP);
130
131 typedef enum _eCustomRoomRenderer {
132         eUseDefault = VIEW_JOURNAL + 100,
133         eReadEUIDS
134 } eCustomRoomRenderer;
135
136 enum {
137         do_search,
138         headers,
139         readfwd,
140         readnew,
141         readold,
142         readgt,
143         readlt
144 };
145
146 /**
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
153  */
154 typedef int (*load_msg_ptrs_detailheaders)(StrBuf * Line,
155                                            const char **pos, message_summary * Msg, StrBuf * ConversionBuffer, void **ViewSpecific);
156
157 typedef void (*readloop_servcmd)(char *buf, long bufsize);
158
159 typedef struct _readloopstruct {
160         ConstStr name;
161         readloop_servcmd cmd;
162 } readloop_struct;
163
164 extern readloop_struct rlid[];
165
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);
171
172
173
174
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? */
179
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? */
182
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 */
187
188         long lowest_found;      /* smallest Message ID found;  */
189         long highest_found;     /* highest Message ID found;  */
190
191 } SharedMessageStatus;
192
193 int load_msg_ptrs(const char *servcmd,
194                   const char *filter,
195                   StrBuf * FoundCharset,
196                   SharedMessageStatus * Stat,
197                   void **ViewSpecific,
198                   load_msg_ptrs_detailheaders LH, StrBuf * FetchMessageList, eMessageField * MessageFieldList, long HeaderCount);
199
200 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus * Stat,
201                                            void **ViewSpecific, long oper, char *cmd, long len, char *filter, long flen);
202
203 typedef int (*PrintViewHeader_func)(SharedMessageStatus * Stat, void **ViewSpecific);
204
205 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus * Stat, void **ViewSpecific, message_summary * Msg, int is_new, int i);
206
207 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus * Stat, void **ViewSpecific, long oper);
208 typedef int (*View_Cleanup_func)(void **ViewSpecific);
209
210 void RegisterReadLoopHandlerset(
211
212         /**
213          * RoomType: which View definition are you going to be called for
214          */
215                                        int RoomType,
216
217         /**
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 
224          *      is skipped.
225          *  * influence the behaviour by presetting values on SharedMessageStatus
226          */
227                                        GetParamsGetServerCall_func GetParamsGetServerCall,
228
229         /**
230          * PrintpageHeader prints the surrounding information like iconbar, header etc.
231          * by default, output_headers() is called.
232          *
233          */
234                                        PrintViewHeader_func PrintPageHeader,
235
236         /**
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.
240          */
241                                        PrintViewHeader_func PrintViewHeader,
242
243         /**
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.
246          */
247                                        load_msg_ptrs_detailheaders LH,
248
249         /**
250          * LoadMsgFromServer is called for every message in the message list:
251          *  * which is 
252          *    * after 'startmsg'  
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.
257          */
258                                        LoadMsgFromServer_func LoadMsgFromServer,
259
260         /**
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.
265          */
266                                        RenderView_or_Tail_func RenderView_or_Tail,
267
268         /**
269          * ViewCleanup should just clear your private data so all your mem can go back to 
270          * VALgrindHALLA.
271          * it also should release the content for delivery via end_burst() or wDumpContent(1);
272          */
273                                        View_Cleanup_func ViewCleanup,
274
275         /**
276          * brofwseListFields schould be a NULL-terminated list of message field mnemonics
277          * that will be the browse vector for the message header list.
278          */
279                                        const char **browseListFields);
280
281 /*
282 GetParamsGetServerCall
283
284 PrintViewHeader
285
286 LoadMsgFromServer
287
288 RenderView_or_Tail
289 */
290
291
292 int ParseMessageListHeaders_Detail(StrBuf * Line,
293                                    const char **pos, message_summary * Msg, StrBuf * ConversionBuffer, void **ViewSpecific);
294
295 /**
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)
301  */
302 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer, int InlineRenderable, int Priority);
303
304
305 /**
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
310  */
311 int ReadOneMessageSummary(message_summary * Msg, StrBuf * FoundCharset, StrBuf * Buf);
312
313 #endif