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