* Enhance the older/newer logic. It's still not quite right.
[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 *from;           /* the author */
35         StrBuf *to;             /* the recipient */
36         StrBuf *subj;           /* the title / subject */
37         StrBuf *reply_inreplyto;
38         StrBuf *reply_references;
39         StrBuf *reply_to;
40         StrBuf *cccc;
41         StrBuf *hnod;
42         StrBuf *AllRcpt;
43         StrBuf *Room;
44         StrBuf *Rfca;
45         StrBuf *OtherNode;
46         const StrBuf *PartNum;
47
48         HashList *Attachments;  /* list of attachments */
49         HashList *Submessages;
50         HashList *AttachLinks;
51
52         HashList *AllAttach;
53
54         int is_new;
55         int hasattachments;
56
57
58         /* The mime part of the message */
59         wc_mime_attachment *MsgBody;
60 } message_summary;
61 void DestroyMessageSummary(void *vMsg);
62 inline message_summary* GetMessagePtrAt(int n, HashList *Summ);
63
64 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
65
66 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime);
67
68 enum {
69         do_search,
70         headers,
71         readfwd,
72         readnew,
73         readold,
74         readgt,
75         readlt
76 };
77
78 typedef void (*readloop_servcmd)(char *buf, long bufsize);
79
80 typedef struct _readloopstruct {
81         ConstStr name;
82         readloop_servcmd cmd;
83 } readloop_struct;
84
85 extern readloop_struct rlid[];
86
87
88 void readloop(long oper);
89 int read_message(StrBuf *Target, 
90                  const char *tmpl, long tmpllen, 
91                  long msgnum, 
92                  const StrBuf *section, 
93                  const StrBuf **OutMime);
94 int load_message(message_summary *Msg, 
95                  StrBuf *FoundCharset,
96                  StrBuf **Error);
97
98
99
100
101 typedef struct _SharedMessageStatus{
102         long load_seen;        /** should read information be loaded */
103         long sortit;           /** should we sort it using the standard sort API? */
104         long defaultsortorder; /** if we should sort it, which direction should be the default? */
105
106         long maxload;          /** how many headers should we accept from the server? defaults to 10k */
107         long maxmsgs;          /** how many message bodies do you want to load at most?*/
108         long reverse;          /** should the load-range be reversed? */
109
110         long startmsg;         /** which is the start message ????? */
111         long nummsgs;          /** How many messages are available to your view? */
112         long num_displayed;    /** counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
113
114         long lowest_found;     /** smallest Message ID found;  */
115         long highest_found;    /** highest Message ID found;  */
116
117 }SharedMessageStatus;
118
119 int load_msg_ptrs(const char *servcmd, SharedMessageStatus *Stat);
120
121 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
122                                            void **ViewSpecific, 
123                                            long oper, 
124                                            char *cmd, 
125                                            long len);
126
127 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
128
129 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
130                                       void **ViewSpecific, 
131                                       message_summary* Msg, 
132                                       int is_new, 
133                                       int i);
134
135 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
136                                        void **ViewSpecific, 
137                                        long oper);
138 typedef int (*View_Cleanup_func)(void **ViewSpecific);
139
140 void RegisterReadLoopHandlerset(
141         /**
142          * RoomType: which View definition are you going to be called for
143          */
144         int RoomType,
145
146         /**
147          * GetParamsGetServerCall should do the following:
148          *  * allocate your private context structure
149          *  * evaluate your commandline arguments, put results to your private struct.
150          *  * fill cmd with the command to load the message pointer list:
151          *    * might depend on bstr/oper depending on your needs
152          *    * might stay empty if no list should loaded and LoadMsgFromServer 
153          *      is skipped.
154          *  * influence the behaviour by presetting values on SharedMessageStatus
155          */
156         GetParamsGetServerCall_func GetParamsGetServerCall,
157
158         /**
159          * PrintViewHeader is here to print informations infront of your messages.
160          * The message list is already loaded & sorted (if) so you can evaluate 
161          * its result on the SharedMessageStatus struct.
162          */
163         PrintViewHeader_func PrintViewHeader,
164
165         /**
166          * LoadMsgFromServer is called for every message in the message list:
167          *  * which is 
168          *    * after 'startmsg'  
169          *    * up to 'maxmsgs' after your 'startmsg'
170          *  * it should load and parse messages from citserer.
171          *  * depending on your needs you might want to print your message here...
172          *  * if cmd was empty, its skipped alltogether.
173          */
174         LoadMsgFromServer_func LoadMsgFromServer,
175
176         /**
177          * RenderView_or_Tail is called last; 
178          *  * if you used PrintViewHeader to print messages, you might want to print 
179          *    trailing information here
180          *  * if you just pre-loaded your messages, put your render code here.
181          */
182         RenderView_or_Tail_func RenderView_or_Tail,
183
184         /**
185          * ViewCleanup should just clear your private data so all your mem can go back to 
186          * VALgrindHALLA.
187          * it also should release the content for delivery via end_burst() or wDumpContent(1);
188          */
189         View_Cleanup_func ViewCleanup
190         );
191 /*
192 GetParamsGetServerCall
193
194 PrintViewHeader
195
196 LoadMsgFromServer
197
198 RenderView_or_Tail
199 */