Back to index

courier  0.68.2
maildirmisc.h
Go to the documentation of this file.
00001 #ifndef       maildirmisc_h
00002 #define       maildirmisc_h
00003 
00004 /*
00005 ** Copyright 2000-2003 Double Precision, Inc.
00006 ** See COPYING for distribution information.
00007 */
00008 
00009 #if    HAVE_CONFIG_H
00010 #include      "config.h"
00011 #endif
00012 
00013 #if HAVE_SYS_STAT_H
00014 #include      <sys/stat.h>
00015 #endif
00016 
00017 #ifdef  __cplusplus
00018 extern "C" {
00019 #endif
00020 
00021 
00022 /*
00023 **
00024 ** Miscellaneous maildir-related code
00025 **
00026 */
00027 
00028 /* Some special folders */
00029 
00030 #define       INBOX  "INBOX"
00031 #define       DRAFTS "Drafts"
00032 #define       SENT   "Sent"
00033 #define       TRASH  "Trash"
00034 #define       SHARED "shared"
00035 
00036 #define       SHAREDSUBDIR  "shared-folders"
00037 
00038 #define NEWSHAREDSP "#shared"
00039 #define       NEWSHARED "#shared."
00040 
00041 #define PUBLIC "public" /* SMAP */
00042 
00043 int maildir_make(const char *maildir, int perm, int subdirperm,
00044               int folder);
00045 
00046 int maildir_del(const char *maildir);
00047 
00048 int maildir_del_content(const char *maildir);
00049 
00050 char *maildir_name2dir(const char *maildir,      /* DIR location */
00051                      const char *foldername); /* INBOX.name */
00052 
00053 char *maildir_location(const char *homedir,
00054                      const char *maildir);
00055 /*
00056 ** Homedir is the account's home directory, "maildir" is where the account's
00057 ** default Maildir is configured to be (usually "./Maildir").  Combine the
00058 ** two to produce an absolute pathname.
00059 */
00060 
00061 
00062 char *maildir_folderdir(const char *,            /* maildir */
00063        const char *);                            /* folder name */
00064        /* Returns the directory corresponding to foldername (foldername is
00065        ** checked to make sure that it's a valid name, else we set errno
00066        ** to EINVAL, and return (0).
00067        */
00068 
00069 char *maildir_filename(const char *,             /* maildir */
00070        const char *,                      /* folder */
00071        const char *);                            /* filename */
00072        /*
00073        ** Builds the filename to this message, suitable for opening.
00074        ** If the file doesn't appear to be there, search the maildir to
00075        ** see if someone changed the flags, and return the current filename.
00076        */
00077 
00078 int maildir_safeopen(const char *,        /* filename */
00079        int,                        /* mode */
00080        int);                       /* perm */
00081 
00082 /*
00083 **     Same arguments as open().  When we're accessing a shared maildir,
00084 **     prevent someone from playing cute and dumping a bunch of symlinks
00085 **     in there.  This function will open the indicate file only if the
00086 **     last component is not a symlink.
00087 **     This is implemented by opening the file with O_NONBLOCK (to prevent
00088 **     a DOS attack of someone pointing the symlink to a pipe, causing
00089 **     the open to hang), clearing O_NONBLOCK, then stat-int the file
00090 **     descriptor, lstating the filename, and making sure that dev/ino
00091 **     match.
00092 */
00093 
00094 int maildir_semisafeopen(const char *,    /* filename */
00095        int,                        /* mode */
00096        int);                       /* perm */
00097 
00098 /*
00099 ** Same thing, except that we allow ONE level of soft link indirection,
00100 ** because we're reading from our own maildir, which points to the
00101 ** message in the sharable maildir.
00102 */
00103 
00104 int maildir_safeopen_stat(const char *path, int mode, int perm,
00105                        struct stat *stat1);
00106        /* Sane as maildir_safeopen(), except that we also initialize a
00107        ** struct stat, saving an extra syscall to the caller.
00108        */
00109 
00110 int maildir_mkdir(const char *);   /* directory */
00111 /*
00112 ** Create maildir including all subdirectories in the path (like mkdir -p)
00113 */
00114 
00115 void maildir_purgetmp(const char *);             /* maildir */
00116        /* purges old stuff out of tmp */
00117 
00118 void maildir_purge(const char *,          /* directory */
00119        unsigned);                         /* time_t to purge */
00120 
00121 void maildir_getnew(const char *,         /* maildir */
00122        const char *,                      /* folder */
00123        void (*)(const char *, void *),           /* Callback function for
00124                                           ** every moved msg.
00125                                           */
00126        void *arg);                        /* Passthrough callback arg */
00127 
00128        /* move messages from new to cur */
00129 
00130 int maildir_deletefolder(const char *,           /* maildir */
00131        const char *);                            /* folder */
00132        /* deletes a folder */
00133 
00134 void maildir_list(const char *maildir,
00135                 void (*func)(const char *, void *),
00136                 void *voidp);
00137 
00138 void maildir_list_sharable(const char *,  /* maildir */
00139        void (*)(const char *, void *),           /* callback function */
00140        void *);                           /* 2nd arg to callback func */
00141        /* list sharable folders */
00142 
00143 int maildir_shared_subscribe(const char *,       /* maildir */
00144               const char *);                     /* folder */
00145        /* subscribe to a shared folder */
00146 
00147 void maildir_list_shared(const char *,           /* maildir */
00148        void (*)(const char *, void *),           /* callback function */
00149        void *);                    /* 2nd arg to the callback func */
00150        /* list subscribed folders */
00151 
00152 int maildir_shared_unsubscribe(const char *,     /* maildir */
00153               const char *);                     /* folder */
00154        /* unsubscribe from a shared folder */
00155 
00156 char *maildir_shareddir(const char *,            /* maildir */
00157        const char *);                            /* folder */
00158        /*
00159        ** Validate and return a path to a shared folder.  folderdir must be
00160        ** a name of a valid shared folder.
00161        */
00162 
00163 void maildir_shared_sync(const char *);          /* maildir */
00164        /* "sync" the shared folder */
00165 
00166 int maildir_sharedisro(const char *);            /* maildir */
00167        /* maildir is a shared read-only folder */
00168 
00169 int maildir_unlinksharedmsg(const char *);       /* filename */
00170        /* Remove a message from a shared folder */
00171 
00172 /* Internal function that reads a symlink */
00173 
00174 char *maildir_getlink(const char *);
00175 
00176        /* Determine whether the maildir filename has a certain flag */
00177 
00178 int maildir_hasflag(const char *filename, char);
00179 
00180 #define       MAILDIR_DELETED(f)   maildir_hasflag((f), 'T')
00181 
00182        /*
00183        ** Hierarchical maildir rename.
00184        */
00185 
00186 #define MAILDIR_RENAME_FOLDER 1
00187 #define MAILDIR_RENAME_SUBFOLDERS 2
00188 
00189 int maildir_rename(const char *maildir, /* Path to the maildir */
00190                  const char *oldname, /* .foldername */
00191                  const char *newname, /* .foldername */
00192                  int flags, /* See above */
00193                  void (*callback_func)(const char *old_path,
00194                                     const char *new_path)
00195                  );
00196 
00197 #ifdef  __cplusplus
00198 }
00199 #endif
00200 
00201 #endif