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