summaryrefslogtreecommitdiffstats
path: root/maildir/maildirpath.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildir/maildirpath.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'maildir/maildirpath.c')
-rw-r--r--maildir/maildirpath.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/maildir/maildirpath.c b/maildir/maildirpath.c
new file mode 100644
index 0000000..f02ede5
--- /dev/null
+++ b/maildir/maildirpath.c
@@ -0,0 +1,127 @@
+/*
+** Copyright 2000 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "maildirmisc.h"
+
+
+char *maildir_name2dir(const char *maildir, /* DIR location */
+ const char *foldername) /* INBOX.name */
+{
+ const char *inbox=INBOX;
+ int l=strlen(inbox);
+ char *p;
+
+ if (!maildir) maildir=".";
+
+ if (foldername && strncasecmp(foldername, INBOX, l) == 0 &&
+ strchr(foldername, '/') == NULL)
+ {
+ if (foldername[l] == 0)
+ return strdup(maildir); /* INBOX: main maildir inbox */
+
+ if (foldername[l] == '.')
+ {
+ const char *r;
+
+ for (r=foldername; *r; r++)
+ {
+ if (*r != '.') continue;
+
+ if (r[1] == 0 || r[1] == '.')
+ {
+ errno=EINVAL;
+ return (0);
+ }
+ }
+
+ r=strchr(foldername, '.');
+
+ p=malloc(strlen(maildir)+strlen(r) + 2);
+
+ if (!p)
+ return NULL;
+
+ return (strcat(strcat(strcpy(p, maildir), "/"),
+ r));
+ }
+ }
+
+ errno=EINVAL;
+ return NULL;
+}
+
+char *maildir_location(const char *homedir,
+ const char *maildir)
+{
+ char *p;
+
+ if (*maildir == '/')
+ return strdup(maildir);
+
+ p=malloc(strlen(homedir)+strlen(maildir)+2);
+
+ if (!p)
+ return NULL;
+ strcat(strcat(strcpy(p, homedir), "/"), maildir);
+ return p;
+}
+
+char *maildir_folderdir(const char *maildir, const char *foldername)
+{
+char *p;
+const char *r;
+size_t l;
+
+ if (!maildir) maildir=".";
+ l=strlen(maildir);
+
+ if (foldername == 0 ||
+ strcasecmp(foldername, INBOX) == 0)
+ {
+ if ((p=malloc(l+1)) == 0) return (0);
+ strcpy(p, maildir);
+ return(p);
+ }
+
+ /* Rules: no leading/trailing periods, no /s */
+ if (*foldername == '.' || strchr(foldername, '/'))
+ {
+ errno=EINVAL;
+ return (0);
+ }
+
+ for (r=foldername; *r; r++)
+ {
+ if (*r != '.') continue;
+ if (r[1] == 0 || r[1] == '.')
+ {
+ errno=EINVAL;
+ return (0);
+ }
+ }
+
+ if ((p=malloc(l+strlen(foldername)+3)) == 0) return (0);
+ *p=0;
+ if (strcmp(maildir, "."))
+ strcat(strcpy(p, maildir), "/");
+
+ return (strcat(strcat(p, "."), foldername));
+}