diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildir/maildirshared2.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-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/maildirshared2.c')
| -rw-r--r-- | maildir/maildirshared2.c | 90 | 
1 files changed, 90 insertions, 0 deletions
| diff --git a/maildir/maildirshared2.c b/maildir/maildirshared2.c new file mode 100644 index 0000000..055a641 --- /dev/null +++ b/maildir/maildirshared2.c @@ -0,0 +1,90 @@ +/* +** Copyright 2000 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include	"config.h" +#include	"maildirmisc.h" +#include	<stdio.h> +#include	<string.h> +#include	<stdlib.h> +#include	<ctype.h> +#include	<errno.h> + + +FILE *maildir_shared_fopen(const char *maildir, const char *mode) +{ +char	*m; +FILE	*fp; + +	m=malloc(strlen(maildir)+sizeof("/shared-maildirs")); +	if (!m) +	{ +		perror("malloc"); +		return (0); +	} +	strcat(strcpy(m, maildir), "/shared-maildirs"); + +	fp=fopen(m, mode); +	free(m); +	return (fp); +} + +void maildir_shared_fparse(char *p, char **name, char **dir) +{ +char	*q; + +	*name=0; +	*dir=0; + +	if ((q=strchr(p, '\n')) != 0)	*q=0; +	if ((q=strchr(p, '#')) != 0)	*q=0; + +	for (q=p; *q; q++) +		if (isspace((int)(unsigned char)*q))	break; +	if (!*q)	return; +	*q++=0; +	while (*q && isspace((int)(unsigned char)*q)) +		++q; +	if (*q) +	{ +		*name=p; +		*dir=q; +	} +} + +char *maildir_shareddir(const char *maildir, const char *sharedname) +{ +char    *p, *q; +const char *r; + +	if (!maildir)   maildir="."; + +	if (strchr(sharedname, '.') == 0 || *sharedname == '.' || +		strchr(sharedname, '/')) +	{ +		errno=EINVAL; +		return (0); +	} + +	for (r=sharedname; *r; r++) +	{ +		if (*r == '.' && (r[1] == '.' || r[1] == '\0')) +		{ +			errno=EINVAL; +			return (0); +		} +	} + +	p=malloc(strlen(maildir)+sizeof("/" SHAREDSUBDIR "/")+strlen(sharedname)); +	if (!p)	return (0); + +        *p=0; +        if (strcmp(maildir, ".")) +		strcat(strcpy(p, maildir), "/"); +	strcat(p, SHAREDSUBDIR "/"); +	q=p+strlen(p); +	strcpy(q, sharedname); +	*strchr(q, '.')='/'; +	return (p); +} | 
