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