]> git.notmuchmail.org Git - notmuch/blob - contrib/notmuch-deliver/maildrop/maildir/maildirmisc.h
e1e7c19acaedc2a011e615065111196141850d43
[notmuch] / contrib / notmuch-deliver / maildrop / maildir / maildirmisc.h
1 #ifndef maildirmisc_h
2 #define maildirmisc_h
3
4 /*
5 ** Copyright 2000-2003 Double Precision, Inc.
6 ** See COPYING for distribution information.
7 */
8
9 #if     HAVE_CONFIG_H
10 #include        "config.h"
11 #endif
12
13 #if HAVE_SYS_STAT_H
14 #include        <sys/stat.h>
15 #endif
16
17 #ifdef  __cplusplus
18 extern "C" {
19 #endif
20
21
22 /*
23 **
24 ** Miscellaneous maildir-related code
25 **
26 */
27
28 /* Some special folders */
29
30 #define INBOX   "INBOX"
31 #define DRAFTS  "Drafts"
32 #define SENT    "Sent"
33 #define TRASH   "Trash"
34 #define SHARED  "shared"
35
36 #define SHAREDSUBDIR    "shared-folders"
37
38 #define NEWSHAREDSP "#shared"
39 #define NEWSHARED "#shared."
40
41 #define PUBLIC "public" /* SMAP */
42
43 int maildir_make(const char *maildir, int perm, int subdirperm,
44                 int folder);
45
46 int maildir_del(const char *maildir);
47
48 int maildir_del_content(const char *maildir);
49
50 char *maildir_name2dir(const char *maildir,     /* DIR location */
51                        const char *foldername); /* INBOX.name */
52
53 char *maildir_location(const char *homedir,
54                        const char *maildir);
55 /*
56 ** Homedir is the account's home directory, "maildir" is where the account's
57 ** default Maildir is configured to be (usually "./Maildir").  Combine the
58 ** two to produce an absolute pathname.
59 */
60
61
62 char *maildir_folderdir(const char *,           /* maildir */
63         const char *);                          /* folder name */
64         /* Returns the directory corresponding to foldername (foldername is
65         ** checked to make sure that it's a valid name, else we set errno
66         ** to EINVAL, and return (0).
67         */
68
69 char *maildir_filename(const char *,            /* maildir */
70         const char *,                           /* folder */
71         const char *);                          /* filename */
72         /*
73         ** Builds the filename to this message, suitable for opening.
74         ** If the file doesn't appear to be there, search the maildir to
75         ** see if someone changed the flags, and return the current filename.
76         */
77
78 int maildir_safeopen(const char *,              /* filename */
79         int,                            /* mode */
80         int);                           /* perm */
81
82 /*
83 **      Same arguments as open().  When we're accessing a shared maildir,
84 **      prevent someone from playing cute and dumping a bunch of symlinks
85 **      in there.  This function will open the indicate file only if the
86 **      last component is not a symlink.
87 **      This is implemented by opening the file with O_NONBLOCK (to prevent
88 **      a DOS attack of someone pointing the symlink to a pipe, causing
89 **      the open to hang), clearing O_NONBLOCK, then stat-int the file
90 **      descriptor, lstating the filename, and making sure that dev/ino
91 **      match.
92 */
93
94 int maildir_semisafeopen(const char *,  /* filename */
95         int,                            /* mode */
96         int);                           /* perm */
97
98 /*
99 ** Same thing, except that we allow ONE level of soft link indirection,
100 ** because we're reading from our own maildir, which points to the
101 ** message in the sharable maildir.
102 */
103
104 int maildir_safeopen_stat(const char *path, int mode, int perm,
105                           struct stat *stat1);
106         /* Sane as maildir_safeopen(), except that we also initialize a
107         ** struct stat, saving an extra syscall to the caller.
108         */
109
110 int maildir_mkdir(const char *);        /* directory */
111 /*
112 ** Create maildir including all subdirectories in the path (like mkdir -p)
113 */
114
115 void maildir_purgetmp(const char *);            /* maildir */
116         /* purges old stuff out of tmp */
117
118 void maildir_purge(const char *,                /* directory */
119         unsigned);                              /* time_t to purge */
120
121 void maildir_getnew(const char *,               /* maildir */
122         const char *,                           /* folder */
123         void (*)(const char *, void *),         /* Callback function for
124                                                 ** every moved msg.
125                                                 */
126         void *arg);                             /* Passthrough callback arg */
127
128         /* move messages from new to cur */
129
130 int maildir_deletefolder(const char *,          /* maildir */
131         const char *);                          /* folder */
132         /* deletes a folder */
133
134 void maildir_list(const char *maildir,
135                   void (*func)(const char *, void *),
136                   void *voidp);
137
138 void maildir_list_sharable(const char *,        /* maildir */
139         void (*)(const char *, void *),         /* callback function */
140         void *);                                /* 2nd arg to callback func */
141         /* list sharable folders */
142
143 int maildir_shared_subscribe(const char *,      /* maildir */
144                 const char *);                  /* folder */
145         /* subscribe to a shared folder */
146
147 void maildir_list_shared(const char *,          /* maildir */
148         void (*)(const char *, void *),         /* callback function */
149         void *);                        /* 2nd arg to the callback func */
150         /* list subscribed folders */
151
152 int maildir_shared_unsubscribe(const char *,    /* maildir */
153                 const char *);                  /* folder */
154         /* unsubscribe from a shared folder */
155
156 char *maildir_shareddir(const char *,           /* maildir */
157         const char *);                          /* folder */
158         /*
159         ** Validate and return a path to a shared folder.  folderdir must be
160         ** a name of a valid shared folder.
161         */
162
163 void maildir_shared_sync(const char *);         /* maildir */
164         /* "sync" the shared folder */
165
166 int maildir_sharedisro(const char *);           /* maildir */
167         /* maildir is a shared read-only folder */
168
169 int maildir_unlinksharedmsg(const char *);      /* filename */
170         /* Remove a message from a shared folder */
171
172 /* Internal function that reads a symlink */
173
174 char *maildir_getlink(const char *);
175
176         /* Determine whether the maildir filename has a certain flag */
177
178 int maildir_hasflag(const char *filename, char);
179
180 #define MAILDIR_DELETED(f)      maildir_hasflag((f), 'T')
181
182         /*
183         ** Hierarchical maildir rename.
184         */
185
186 #define MAILDIR_RENAME_FOLDER 1
187 #define MAILDIR_RENAME_SUBFOLDERS 2
188
189 int maildir_rename(const char *maildir, /* Path to the maildir */
190                    const char *oldname, /* .foldername */
191                    const char *newname, /* .foldername */
192                    int flags, /* See above */
193                    void (*callback_func)(const char *old_path,
194                                          const char *new_path)
195                    );
196
197 #ifdef  __cplusplus
198 }
199 #endif
200
201 #endif