5 ** Copyright 2000-2003 Double Precision, Inc.
6 ** See COPYING for distribution information.
21 static const char maildirmisc_h_rcsid[]="$Id: maildirmisc.h,v 1.18 2006/07/22 02:48:15 mrsam Exp $";
25 ** Miscellaneous maildir-related code
29 /* Some special folders */
32 #define DRAFTS "Drafts"
35 #define SHARED "shared"
37 #define SHAREDSUBDIR "shared-folders"
39 #define NEWSHAREDSP "#shared"
40 #define NEWSHARED "#shared."
42 #define PUBLIC "public" /* SMAP */
44 int maildir_make(const char *maildir, int perm, int subdirperm,
47 int maildir_del(const char *maildir);
49 int maildir_del_content(const char *maildir);
51 char *maildir_name2dir(const char *maildir, /* DIR location */
52 const char *foldername); /* INBOX.name */
54 char *maildir_location(const char *homedir,
57 ** Homedir is the account's home directory, "maildir" is where the account's
58 ** default Maildir is configured to be (usually "./Maildir"). Combine the
59 ** two to produce an absolute pathname.
63 char *maildir_folderdir(const char *, /* maildir */
64 const char *); /* folder name */
65 /* Returns the directory corresponding to foldername (foldername is
66 ** checked to make sure that it's a valid name, else we set errno
67 ** to EINVAL, and return (0).
70 char *maildir_filename(const char *, /* maildir */
71 const char *, /* folder */
72 const char *); /* filename */
74 ** Builds the filename to this message, suitable for opening.
75 ** If the file doesn't appear to be there, search the maildir to
76 ** see if someone changed the flags, and return the current filename.
79 int maildir_safeopen(const char *, /* filename */
84 ** Same arguments as open(). When we're accessing a shared maildir,
85 ** prevent someone from playing cute and dumping a bunch of symlinks
86 ** in there. This function will open the indicate file only if the
87 ** last component is not a symlink.
88 ** This is implemented by opening the file with O_NONBLOCK (to prevent
89 ** a DOS attack of someone pointing the symlink to a pipe, causing
90 ** the open to hang), clearing O_NONBLOCK, then stat-int the file
91 ** descriptor, lstating the filename, and making sure that dev/ino
95 int maildir_semisafeopen(const char *, /* filename */
100 ** Same thing, except that we allow ONE level of soft link indirection,
101 ** because we're reading from our own maildir, which points to the
102 ** message in the sharable maildir.
105 int maildir_safeopen_stat(const char *path, int mode, int perm,
107 /* Sane as maildir_safeopen(), except that we also initialize a
108 ** struct stat, saving an extra syscall to the caller.
111 int maildir_mkdir(const char *); /* directory */
113 ** Create maildir including all subdirectories in the path (like mkdir -p)
116 void maildir_purgetmp(const char *); /* maildir */
117 /* purges old stuff out of tmp */
119 void maildir_purge(const char *, /* directory */
120 unsigned); /* time_t to purge */
122 void maildir_getnew(const char *, /* maildir */
123 const char *, /* folder */
124 void (*)(const char *, void *), /* Callback function for
127 void *arg); /* Passthrough callback arg */
129 /* move messages from new to cur */
131 int maildir_deletefolder(const char *, /* maildir */
132 const char *); /* folder */
133 /* deletes a folder */
135 void maildir_list(const char *maildir,
136 void (*func)(const char *, void *),
139 void maildir_list_sharable(const char *, /* maildir */
140 void (*)(const char *, void *), /* callback function */
141 void *); /* 2nd arg to callback func */
142 /* list sharable folders */
144 int maildir_shared_subscribe(const char *, /* maildir */
145 const char *); /* folder */
146 /* subscribe to a shared folder */
148 void maildir_list_shared(const char *, /* maildir */
149 void (*)(const char *, void *), /* callback function */
150 void *); /* 2nd arg to the callback func */
151 /* list subscribed folders */
153 int maildir_shared_unsubscribe(const char *, /* maildir */
154 const char *); /* folder */
155 /* unsubscribe from a shared folder */
157 char *maildir_shareddir(const char *, /* maildir */
158 const char *); /* folder */
160 ** Validate and return a path to a shared folder. folderdir must be
161 ** a name of a valid shared folder.
164 void maildir_shared_sync(const char *); /* maildir */
165 /* "sync" the shared folder */
167 int maildir_sharedisro(const char *); /* maildir */
168 /* maildir is a shared read-only folder */
170 int maildir_unlinksharedmsg(const char *); /* filename */
171 /* Remove a message from a shared folder */
173 /* Internal function that reads a symlink */
175 char *maildir_getlink(const char *);
177 /* Determine whether the maildir filename has a certain flag */
179 int maildir_hasflag(const char *filename, char);
181 #define MAILDIR_DELETED(f) maildir_hasflag((f), 'T')
184 ** Hierarchical maildir rename.
187 #define MAILDIR_RENAME_FOLDER 1
188 #define MAILDIR_RENAME_SUBFOLDERS 2
190 int maildir_rename(const char *maildir, /* Path to the maildir */
191 const char *oldname, /* .foldername */
192 const char *newname, /* .foldername */
193 int flags, /* See above */
194 void (*callback_func)(const char *old_path,
195 const char *new_path)