Choose default sender email address by envelope recipient
[citadel.git] / webcit / messages.h
1 extern CtxType CTX_MAILSUM;
2 extern CtxType CTX_MIME_ATACH;
3 extern HashList *MsgHeaderHandler;
4 extern HashList *MimeRenderHandler;
5 extern HashList *ReadLoopHandler;
6 typedef struct wc_mime_attachment wc_mime_attachment;
7 typedef void (*RenderMimeFunc)(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset);
8 typedef struct _RenderMimeFuncStruct {
9         RenderMimeFunc f;
10 } RenderMimeFuncStruct;
11
12 struct wc_mime_attachment {
13         int level;
14         StrBuf *Name;
15         StrBuf *FileName;
16         StrBuf *PartNum;
17         StrBuf *Disposition;
18         StrBuf *ContentType;
19         StrBuf *Charset;
20         StrBuf *Data;
21         size_t length;          /* length of the mimeattachment */
22         long size_known;
23         long lvalue;            /* if we put a long... */
24         long msgnum;            /* the message number on the citadel server derived from message_summary */
25         const RenderMimeFuncStruct *Renderer;
26 };
27 void DestroyMime(void *vMime);
28
29 #define MSGFLAG_READ (1<<0)
30
31 typedef struct _message_summary {
32         long msgnum;            /* the message number on the citadel server */
33         int Flags;
34
35         time_t date;            /* its creation date */
36         int nhdr;
37         int format_type;
38         StrBuf *euid;
39         StrBuf *from;           /* the author */
40         StrBuf *to;             /* the recipient */
41         StrBuf *subj;           /* the title / subject */
42         StrBuf *reply_inreplyto;
43         StrBuf *reply_references;
44         StrBuf *ReplyTo;
45         StrBuf *cccc;
46         StrBuf *hnod;
47         StrBuf *AllRcpt;
48         StrBuf *Room;
49         StrBuf *Rfca;
50         StrBuf *EnvTo;
51         StrBuf *OtherNode;
52         const StrBuf *PartNum;
53
54         HashList *Attachments;  /* list of attachments */
55         HashList *Submessages;
56         HashList *AttachLinks;
57
58         HashList *AllAttach;
59
60         int hasattachments;
61
62
63         /* The mime part of the message */
64         wc_mime_attachment *MsgBody;
65 } message_summary;
66 void DestroyMessageSummary(void *vMsg);
67
68
69
70 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
71 {
72         const char *Key;
73         long HKLen;
74         void *vMsg;
75
76         if (Summ == NULL)
77                 return NULL;
78         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
79         return (message_summary*) vMsg;
80 }
81
82 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
83
84 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
85
86
87 typedef enum _eCustomRoomRenderer {
88         eUseDefault = VIEW_JOURNAL + 100, 
89         eReadEUIDS
90 }eCustomRoomRenderer;
91
92 enum {
93         do_search,
94         headers,
95         readfwd,
96         readnew,
97         readold,
98         readgt,
99         readlt
100 };
101
102 /**
103  * @brief function to parse the | separated message headers list
104  * @param Line the raw line with your message data
105  * @param Msg put your parser results here...
106  * @param ConversionBuffer if you need some workbuffer, don't free me!
107  * @returns 0: failure, trash this message. 1: all right, store it
108  */
109 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line, 
110                                             const char **pos, 
111                                             message_summary *Msg, 
112                                             StrBuf *ConversionBuffer);
113
114 typedef void (*readloop_servcmd)(char *buf, long bufsize);
115
116 typedef struct _readloopstruct {
117         ConstStr name;
118         readloop_servcmd cmd;
119 } readloop_struct;
120
121 extern readloop_struct rlid[];
122
123 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
124 int read_message(StrBuf *Target, 
125                  const char *tmpl, long tmpllen, 
126                  long msgnum, 
127                  const StrBuf *section, 
128                  const StrBuf **OutMime);
129 int load_message(message_summary *Msg, 
130                  StrBuf *FoundCharset,
131                  StrBuf **Error);
132
133
134
135
136 typedef struct _SharedMessageStatus {
137         long load_seen;        /* should read information be loaded */
138         long sortit;           /* should we sort it using the standard sort API? */
139         long defaultsortorder; /* if we should sort it, which direction should be the default? */
140
141         long maxload;          /* how many headers should we accept from the server? defaults to 10k */
142         long maxmsgs;          /* how many message bodies do you want to load at most?*/
143
144         long startmsg;         /* which is the start message? */
145         long nummsgs;          /* How many messages are available to your view? */
146         long num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
147
148         long lowest_found;     /* smallest Message ID found;  */
149         long highest_found;    /* highest Message ID found;  */
150
151 } SharedMessageStatus;
152
153 int load_msg_ptrs(const char *servcmd,
154                   const char *filter,
155                   SharedMessageStatus *Stat, 
156                   load_msg_ptrs_detailheaders LH);
157
158 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
159                                            void **ViewSpecific, 
160                                            long oper, 
161                                            char *cmd, 
162                                            long len,
163                                            char *filter,
164                                            long flen);
165
166 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
167
168 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
169                                       void **ViewSpecific, 
170                                       message_summary* Msg, 
171                                       int is_new, 
172                                       int i);
173
174 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
175                                        void **ViewSpecific, 
176                                        long oper);
177 typedef int (*View_Cleanup_func)(void **ViewSpecific);
178
179 void RegisterReadLoopHandlerset(
180         /**
181          * RoomType: which View definition are you going to be called for
182          */
183         int RoomType,
184
185         /**
186          * GetParamsGetServerCall should do the following:
187          *  * allocate your private context structure
188          *  * evaluate your commandline arguments, put results to your private struct.
189          *  * fill cmd with the command to load the message pointer list:
190          *    * might depend on bstr/oper depending on your needs
191          *    * might stay empty if no list should loaded and LoadMsgFromServer 
192          *      is skipped.
193          *  * influence the behaviour by presetting values on SharedMessageStatus
194          */
195         GetParamsGetServerCall_func GetParamsGetServerCall,
196
197         /**
198          * PrintpageHeader prints the surrounding information like iconbar, header etc.
199          * by default, output_headers() is called.
200          *
201          */
202         PrintViewHeader_func PrintPageHeader,
203
204         /**
205          * PrintViewHeader is here to print informations infront of your messages.
206          * The message list is already loaded & sorted (if) so you can evaluate 
207          * its result on the SharedMessageStatus struct.
208          */
209         PrintViewHeader_func PrintViewHeader,
210
211         /**
212          * LH is the function, you specify if you want to load more than just message
213          * numbers from the server during the listing fetch operation.
214          */
215         load_msg_ptrs_detailheaders LH,
216
217         /**
218          * LoadMsgFromServer is called for every message in the message list:
219          *  * which is 
220          *    * after 'startmsg'  
221          *    * up to 'maxmsgs' after your 'startmsg'
222          *  * it should load and parse messages from citserer.
223          *  * depending on your needs you might want to print your message here...
224          *  * if cmd was empty, its skipped alltogether.
225          */
226         LoadMsgFromServer_func LoadMsgFromServer,
227
228         /**
229          * RenderView_or_Tail is called last; 
230          *  * if you used PrintViewHeader to print messages, you might want to print 
231          *    trailing information here
232          *  * if you just pre-loaded your messages, put your render code here.
233          */
234         RenderView_or_Tail_func RenderView_or_Tail,
235
236         /**
237          * ViewCleanup should just clear your private data so all your mem can go back to 
238          * VALgrindHALLA.
239          * it also should release the content for delivery via end_burst() or wDumpContent(1);
240          */
241         View_Cleanup_func ViewCleanup
242         );
243 /*
244 GetParamsGetServerCall
245
246 PrintViewHeader
247
248 LoadMsgFromServer
249
250 RenderView_or_Tail
251 */
252
253
254 int ParseMessageListHeaders_Detail(StrBuf *Line, 
255                                    const char **pos, 
256                                    message_summary *Msg, 
257                                    StrBuf *ConversionBuffer);
258
259
260
261 /**
262  * @brief function to register the availability to render a specific message
263  * @param HeaderName Mimetype we know howto display
264  * @param HdrNLen length...
265  * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
266  * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
267  */
268 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
269                           RenderMimeFunc MimeRenderer,
270                           int InlineRenderable,
271                           int Priority);