5 ** Copyright 2000-2003 Double Precision, Inc.
6 ** See COPYING for distribution information.
24 ** Miscellaneous maildir-related code
28 /* Some special folders */
31 #define DRAFTS "Drafts"
34 #define SHARED "shared"
36 #define SHAREDSUBDIR "shared-folders"
38 #define NEWSHAREDSP "#shared"
39 #define NEWSHARED "#shared."
41 #define PUBLIC "public" /* SMAP */
43 int maildir_make(const char *maildir, int perm, int subdirperm,
46 int maildir_del(const char *maildir);
48 int maildir_del_content(const char *maildir);
50 char *maildir_name2dir(const char *maildir, /* DIR location */
51 const char *foldername); /* INBOX.name */
53 char *maildir_location(const char *homedir,
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.
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).
69 char *maildir_filename(const char *, /* maildir */
70 const char *, /* folder */
71 const char *); /* filename */
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.
78 int maildir_safeopen(const char *, /* filename */
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
94 int maildir_semisafeopen(const char *, /* filename */
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.
104 int maildir_safeopen_stat(const char *path, int mode, int perm,
106 /* Sane as maildir_safeopen(), except that we also initialize a
107 ** struct stat, saving an extra syscall to the caller.
110 int maildir_mkdir(const char *); /* directory */
112 ** Create maildir including all subdirectories in the path (like mkdir -p)
115 void maildir_purgetmp(const char *); /* maildir */
116 /* purges old stuff out of tmp */
118 void maildir_purge(const char *, /* directory */
119 unsigned); /* time_t to purge */
121 void maildir_getnew(const char *, /* maildir */
122 const char *, /* folder */
123 void (*)(const char *, void *), /* Callback function for
126 void *arg); /* Passthrough callback arg */
128 /* move messages from new to cur */
130 int maildir_deletefolder(const char *, /* maildir */
131 const char *); /* folder */
132 /* deletes a folder */
134 void maildir_list(const char *maildir,
135 void (*func)(const char *, void *),
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 */
143 int maildir_shared_subscribe(const char *, /* maildir */
144 const char *); /* folder */
145 /* subscribe to a shared folder */
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 */
152 int maildir_shared_unsubscribe(const char *, /* maildir */
153 const char *); /* folder */
154 /* unsubscribe from a shared folder */
156 char *maildir_shareddir(const char *, /* maildir */
157 const char *); /* folder */
159 ** Validate and return a path to a shared folder. folderdir must be
160 ** a name of a valid shared folder.
163 void maildir_shared_sync(const char *); /* maildir */
164 /* "sync" the shared folder */
166 int maildir_sharedisro(const char *); /* maildir */
167 /* maildir is a shared read-only folder */
169 int maildir_unlinksharedmsg(const char *); /* filename */
170 /* Remove a message from a shared folder */
172 /* Internal function that reads a symlink */
174 char *maildir_getlink(const char *);
176 /* Determine whether the maildir filename has a certain flag */
178 int maildir_hasflag(const char *filename, char);
180 #define MAILDIR_DELETED(f) maildir_hasflag((f), 'T')
183 ** Hierarchical maildir rename.
186 #define MAILDIR_RENAME_FOLDER 1
187 #define MAILDIR_RENAME_SUBFOLDERS 2
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)