6ba7603ef5d1de5b257f64428fdc68f52a4ebde5
[citadel.git] / citadel / msgbase.h
1
2 #ifndef MSGBASE_H
3 #define MSGBASE_H
4
5 enum {
6         MSGS_ALL,
7         MSGS_OLD,
8         MSGS_NEW,
9         MSGS_FIRST,
10         MSGS_LAST,
11         MSGS_GT,
12         MSGS_EQ,
13         MSGS_SEARCH,
14         MSGS_LT
15 };
16
17 enum {
18         MSG_HDRS_BRIEF = 0,
19         MSG_HDRS_ALL = 1,
20         MSG_HDRS_EUID = 4,
21         MSG_HDRS_BRIEFFILTER = 8,
22         MSG_HDRS_THREADS = 9
23 };
24
25 /*
26  * Possible return codes from CtdlOutputMsg()
27  */
28 enum {
29         om_ok,
30         om_not_logged_in,
31         om_no_such_msg,
32         om_mime_error,
33         om_access_denied
34 };
35
36 /*
37  * Values of "headers_only" when calling message output routines
38  */
39 #define HEADERS_ALL     0       /* Headers and body */
40 #define HEADERS_ONLY    1       /* Headers only */
41 #define HEADERS_NONE    2       /* Body only */
42 #define HEADERS_FAST    3       /* Headers only with no MIME info */
43
44
45 struct ma_info {
46         int is_ma;              /* Set to 1 if we are using this stuff */
47         int freeze;             /* Freeze the replacement chain because we're
48                                  * digging through a subsection */
49         int did_print;          /* One alternative has been displayed */
50         char chosen_part[128];  /* Which part of a m/a did we choose? */
51         int chosen_pref;        /* Chosen part preference level (lower is better) */
52         int use_fo_hooks;       /* Use fixed output hooks */
53         int dont_decode;        /* should we call the decoder or not? */
54 };
55
56
57 struct repl {                   /* Info for replication checking */
58         char exclusive_id[SIZ];
59         time_t highest;
60 };
61
62
63
64 /*
65  * This is a list of "harvested" email addresses that we might want to
66  * stick into someone's address book.  But we defer this operaiton so
67  * it can be done asynchronously.
68  */
69 struct addresses_to_be_filed {
70         struct addresses_to_be_filed *next;
71         char *roomname;
72         char *collected_addresses;
73 };
74
75 extern struct addresses_to_be_filed *atbf;
76
77 int GetFieldFromMnemonic(eMsgField *f, const char* c);
78 void memfmout (char *mptr, const char *nl);
79 void output_mime_parts(char *);
80 long send_message (struct CtdlMessage *);
81 void loadtroom (void);
82 long CtdlSubmitMsg(struct CtdlMessage *, recptypes *, const char *, int);
83 long quickie_message(const char *from, const char *fromaddr, const char *to, char *room, const char *text, int format_type, const char *subject);
84 void GetMetaData(struct MetaData *, long);
85 void PutMetaData(struct MetaData *);
86 void AdjRefCount(long, int);
87 void TDAP_AdjRefCount(long, int);
88 int TDAP_ProcessAdjRefCountQueue(void);
89 void simple_listing(long, void *);
90 int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template);
91 typedef void (*ForEachMsgCallback)(long MsgNumber, void *UserData);
92 int CtdlForEachMessage(int mode,
93                         long ref,
94                         char *searchstring,
95                         char *content_type,
96                         struct CtdlMessage *compare,
97                         ForEachMsgCallback CallBack,
98                         void *userdata);
99 int CtdlDeleteMessages(const char *, long *, int, char *);
100 void CtdlWriteObject(char *req_room,                    /* Room to stuff it in */
101                         char *content_type,             /* MIME type of this object */
102                         char *raw_message,              /* Data to be written */
103                         off_t raw_length,               /* Size of raw_message */
104                         struct ctdluser *is_mailbox,    /* Mailbox room? */
105                         int is_binary,                  /* Is encoding necessary? */
106                         int is_unique,                  /* Del others of this type? */
107                         unsigned int flags              /* Internal save flags */
108 );
109 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hooks);
110 struct CtdlMessage * CM_Duplicate
111                        (struct CtdlMessage *OrgMsg);
112 int  CM_IsEmpty        (struct CtdlMessage *Msg, eMsgField which);
113 void CM_SetField       (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
114 void CM_SetFieldLONG   (struct CtdlMessage *Msg, eMsgField which, long lvalue);
115 void CM_CopyField      (struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy);
116 void CM_CutFieldAt     (struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen);
117 void CM_FlushField     (struct CtdlMessage *Msg, eMsgField which);
118 void CM_Flush          (struct CtdlMessage *Msg);
119 void CM_SetAsField     (struct CtdlMessage *Msg, eMsgField which, char **buf, long length);
120 void CM_SetAsFieldSB   (struct CtdlMessage *Msg, eMsgField which, StrBuf **buf);
121 void CM_GetAsField     (struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen);
122 void CM_PrependToField (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
123
124 void CM_Free           (struct CtdlMessage *msg);
125 void CM_FreeContents   (struct CtdlMessage *msg);
126 int  CM_IsValidMsg     (struct CtdlMessage *msg);
127
128 #define CM_KEY(Message, Which) Message->cm_fields[Which], Message->cm_lengths[Which]
129 #define CM_RANGE(Message, Which) Message->cm_fields[Which], \
130                 Message->cm_fields[Which] + Message->cm_lengths[Which]
131
132 void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *);
133 struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
134 void ReplicationChecks(struct CtdlMessage *);
135 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
136                               int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj
137 );
138 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
139 long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply);
140 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf);
141 StrBuf *CtdlReadMessageBodyBuf(
142                 char *terminator,       /* token signalling EOT */
143                 long tlen,
144                 size_t maxlen,          /* maximum message length */
145                 StrBuf *exist,          /* if non-null, append to it; exist is ALWAYS freed  */
146                 int crlf                /* CRLF newlines instead of LF */
147 );
148
149 int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
150                 int mode,               /* how would you like that message? */
151                 int headers_only,       /* eschew the message body? */
152                 int do_proto,           /* do Citadel protocol responses? */
153                 int crlf,               /* 0=LF, 1=CRLF */
154                 char *section,          /* output a message/rfc822 section */
155                 int flags,              /* should the bessage be exported clean? */
156                 char **Author,          /* if you want to know the author of the message... */
157                 char **Address,         /* if you want to know the sender address of the message... */
158                 char **MessageID        /* if you want to know the Message-ID of the message... */
159 );
160
161 /* Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg() */
162 #define QP_EADDR        (1<<0)          /* quoted-printable encode email addresses */
163 #define CRLF            (1<<1)
164 #define ESC_DOT         (1<<2)          /* output a line containing only "." as ".." instead */
165 #define SUPPRESS_ENV_TO (1<<3)          /* suppress Envelope-to: header (warning: destructive!) */
166
167 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
168                            int mode,            /* how would you like that message? */
169                            int headers_only,    /* eschew the message body? */
170                            int do_proto,        /* do Citadel protocol responses? */
171                            int crlf,            /* 0=LF, 1=CRLF */
172                            int flags            /* should the bessage be exported clean? */
173 );
174
175
176 /* values for which_set */
177 enum {
178         ctdlsetseen_seen,
179         ctdlsetseen_answered
180 };
181
182 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
183         int target_setting, int which_set,
184         struct ctdluser *which_user, struct ctdlroom *which_room
185 );
186
187 void CtdlGetSeen(char *buf, int which_set);
188
189
190 struct CtdlMessage *CtdlMakeMessage(
191         struct ctdluser *author,        /* author's user structure */
192         char *recipient,                /* NULL if it's not mail */
193         char *recp_cc,                  /* NULL if it's not mail */
194         char *room,                     /* room where it's going */
195         int type,                       /* see MES_ types in header file */
196         int format_type,                /* variformat, plain text, MIME... */
197         char *fake_name,                /* who we're masquerading as */
198         char *my_email,                 /* which of my email addresses to use (empty is ok) */
199         char *subject,                  /* Subject (optional) */
200         char *supplied_euid,            /* ...or NULL if this is irrelevant */
201         char *preformatted_text,        /* ...or NULL to read text from client */
202         char *references                /* Thread references */
203 );
204
205 struct CtdlMessage *CtdlMakeMessageLen(
206         struct ctdluser *author,        /* author's user structure */
207         char *recipient,                /* NULL if it's not mail */
208         long rcplen,
209         char *recp_cc,                  /* NULL if it's not mail */
210         long cclen,
211         char *room,                     /* room where it's going */
212         long roomlen,
213         int type,                       /* see MES_ types in header file */
214         int format_type,                /* variformat, plain text, MIME... */
215         char *fake_name,                /* who we're masquerading as */
216         long fnlen,
217         char *my_email,                 /* which of my email addresses to use (empty is ok) */
218         long myelen,
219         char *subject,                  /* Subject (optional) */
220         long subjlen,
221         char *supplied_euid,            /* ...or NULL if this is irrelevant */
222         long euidlen,
223         char *preformatted_text,        /* ...or NULL to read text from client */
224         long textlen,
225         char *references,               /* Thread references */
226         long reflen
227 );
228
229 void AdjRefCountList(long *msgnum, long nmsg, int incr);
230
231 #endif /* MSGBASE_H */