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 static const char maildirmisc_h_rcsid[]="$Id: maildirmisc.h,v 1.18 2006/07/22 02:48:15 mrsam Exp $"; 22 23 /* 24 ** 25 ** Miscellaneous maildir-related code 26 ** 27 */ 28 29 /* Some special folders */ 30 31 #define INBOX "INBOX" 32 #define DRAFTS "Drafts" 33 #define SENT "Sent" 34 #define TRASH "Trash" 35 #define SHARED "shared" 36 37 #define SHAREDSUBDIR "shared-folders" 38 39 #define NEWSHAREDSP "#shared" 40 #define NEWSHARED "#shared." 41 42 #define PUBLIC "public" /* SMAP */ 43 44 int maildir_make(const char *maildir, int perm, int subdirperm, 45 int folder); 46 47 int maildir_del(const char *maildir); 48 49 int maildir_del_content(const char *maildir); 50 51 char *maildir_name2dir(const char *maildir, /* DIR location */ 52 const char *foldername); /* INBOX.name */ 53 54 char *maildir_location(const char *homedir, 55 const char *maildir); 56 /* 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. 60 */ 61 62 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). 68 */ 69 70 char *maildir_filename(const char *, /* maildir */ 71 const char *, /* folder */ 72 const char *); /* filename */ 73 /* 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. 77 */ 78 79 int maildir_safeopen(const char *, /* filename */ 80 int, /* mode */ 81 int); /* perm */ 82 83 /* 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 92 ** match. 93 */ 94 95 int maildir_semisafeopen(const char *, /* filename */ 96 int, /* mode */ 97 int); /* perm */ 98 99 /* 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. 103 */ 104 105 int maildir_safeopen_stat(const char *path, int mode, int perm, 106 struct stat *stat1); 107 /* Sane as maildir_safeopen(), except that we also initialize a 108 ** struct stat, saving an extra syscall to the caller. 109 */ 110 111 int maildir_mkdir(const char *); /* directory */ 112 /* 113 ** Create maildir including all subdirectories in the path (like mkdir -p) 114 */ 115 116 void maildir_purgetmp(const char *); /* maildir */ 117 /* purges old stuff out of tmp */ 118 119 void maildir_purge(const char *, /* directory */ 120 unsigned); /* time_t to purge */ 121 122 void maildir_getnew(const char *, /* maildir */ 123 const char *, /* folder */ 124 void (*)(const char *, void *), /* Callback function for 125 ** every moved msg. 126 */ 127 void *arg); /* Passthrough callback arg */ 128 129 /* move messages from new to cur */ 130 131 int maildir_deletefolder(const char *, /* maildir */ 132 const char *); /* folder */ 133 /* deletes a folder */ 134 135 void maildir_list(const char *maildir, 136 void (*func)(const char *, void *), 137 void *voidp); 138 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 */ 143 144 int maildir_shared_subscribe(const char *, /* maildir */ 145 const char *); /* folder */ 146 /* subscribe to a shared folder */ 147 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 */ 152 153 int maildir_shared_unsubscribe(const char *, /* maildir */ 154 const char *); /* folder */ 155 /* unsubscribe from a shared folder */ 156 157 char *maildir_shareddir(const char *, /* maildir */ 158 const char *); /* folder */ 159 /* 160 ** Validate and return a path to a shared folder. folderdir must be 161 ** a name of a valid shared folder. 162 */ 163 164 void maildir_shared_sync(const char *); /* maildir */ 165 /* "sync" the shared folder */ 166 167 int maildir_sharedisro(const char *); /* maildir */ 168 /* maildir is a shared read-only folder */ 169 170 int maildir_unlinksharedmsg(const char *); /* filename */ 171 /* Remove a message from a shared folder */ 172 173 /* Internal function that reads a symlink */ 174 175 char *maildir_getlink(const char *); 176 177 /* Determine whether the maildir filename has a certain flag */ 178 179 int maildir_hasflag(const char *filename, char); 180 181 #define MAILDIR_DELETED(f) maildir_hasflag((f), 'T') 182 183 /* 184 ** Hierarchical maildir rename. 185 */ 186 187 #define MAILDIR_RENAME_FOLDER 1 188 #define MAILDIR_RENAME_SUBFOLDERS 2 189 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) 196 ); 197 198 #ifdef __cplusplus 199 } 200 #endif 201 202 #endif 203