1 /* append.h -- Description of messages to be copied
2  *
3  * Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. The name "Carnegie Mellon University" must not be used to
18  *    endorse or promote products derived from this software without
19  *    prior written permission. For permission or any legal
20  *    details, please contact
21  *      Carnegie Mellon University
22  *      Center for Technology Transfer and Enterprise Creation
23  *      4615 Forbes Avenue
24  *      Suite 302
25  *      Pittsburgh, PA  15213
26  *      (412) 268-7393, fax: (412) 268-7395
27  *      innovation@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  */
42 
43 #ifndef INCLUDED_APPEND_H
44 #define INCLUDED_APPEND_H
45 
46 #include "mailbox.h"
47 #include "mboxevent.h"
48 #include "message.h"
49 #include "prot.h"
50 #include "sequence.h"
51 #include "strarray.h"
52 #include "annotate.h"
53 #include "conversations.h"
54 
55 /* it's ridiculous i have to expose this structure if i want to allow
56    clients to stack-allocate it */
57 struct appendstate {
58     /* mailbox we're appending to */
59     struct mailbox *mailbox;
60     /* do we own it? */
61     int close_mailbox_when_done:1;
62     int isoutbox:1;
63     int myrights;
64     char userid[MAX_MAILBOX_BUFFER];
65 
66     enum { APPEND_READY, APPEND_DONE } s;
67                                 /* current state of append */
68 
69     int nummsg;    /* number of messages appended pending commit.
70                       from as->baseuid ... m.baseuid + nummsg - 1 */
71     unsigned baseuid;
72 
73     /* set seen on these message on commit */
74     int internalseen;
75     struct seqset *seen_seq;
76 
77     /* for annotations */
78     const struct namespace *namespace;
79     const struct auth_state *auth_state;
80     int isadmin;
81 
82     /* one event notification to send per appended message */
83     enum event_type event_type;
84     struct mboxevent *mboxevents;
85 };
86 
87 /* add helper function to determine uid range appended? */
88 
89 struct stagemsg;
90 
91 extern int append_check(const char *name,
92                         struct auth_state *auth_state,
93                         long aclcheck,
94                         const quota_t quotacheck[QUOTA_NUMRESOURCES]);
95 
96 /* appendstate must be allocated by client */
97 extern int append_setup(struct appendstate *as, const char *name,
98                         const char *userid, const struct auth_state *auth_state,
99                         long aclcheck,
100                         const quota_t quotacheck[QUOTA_NUMRESOURCES],
101                         const struct namespace *, int isadmin, enum event_type event_type);
102 extern int append_setup_mbox(struct appendstate *as, struct mailbox *mailbox,
103                              const char *userid,
104                              const struct auth_state *auth_state,
105                              long aclcheck,
106                              const quota_t quotacheck[QUOTA_NUMRESOURCES],
107                              const struct namespace *namespace,
108                              int isadmin, enum event_type event_type);
109 
110 extern uint32_t append_uidvalidity(struct appendstate *as);
111 
112 extern int append_commit(struct appendstate *as);
113 extern int append_abort(struct appendstate *as);
114 
115 /* creates a new stage and returns stage file corresponding to mailboxname */
116 extern FILE *append_newstage(const char *mailboxname, time_t internaldate,
117                              int msgnum, struct stagemsg **stagep);
118 
119 /* adds a new mailbox to the stage initially created by append_newstage() */
120 extern int append_fromstage(struct appendstate *mailbox, struct body **body,
121                             struct stagemsg *stage, time_t internaldate,
122                             const strarray_t *flags, int nolink,
123                             struct entryattlist *annotations);
124 
125 /* removes the stage (frees memory, deletes the staging files) */
126 extern int append_removestage(struct stagemsg *stage);
127 
128 extern int append_fromstream(struct appendstate *as, struct body **body,
129                              struct protstream *messagefile,
130                              unsigned long size, time_t internaldate,
131                              const strarray_t *flags);
132 
133 extern int append_copy(struct mailbox *mailbox,
134                        struct appendstate *append_mailbox,
135                        int nummsg, struct index_record *records,
136                        int nolink, int is_same_user);
137 
138 extern int append_collectnews(struct appendstate *mailbox,
139                               const char *group, unsigned long feeduid);
140 
141 #define append_getuidvalidity(as) ((as)->m.uidvalidity)
142 #define append_getlastuid(as) ((as)->m.last_uid)
143 
144 extern int append_run_annotator(struct appendstate *as,
145                                 struct index_record *record);
146 
147 extern const char *append_stagefname(struct stagemsg *stage);
148 
149 #endif /* INCLUDED_APPEND_H */
150