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 /sqwebmail/mailinglist.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 'sqwebmail/mailinglist.c')
| -rw-r--r-- | sqwebmail/mailinglist.c | 77 | 
1 files changed, 77 insertions, 0 deletions
| diff --git a/sqwebmail/mailinglist.c b/sqwebmail/mailinglist.c new file mode 100644 index 0000000..dc5da7c --- /dev/null +++ b/sqwebmail/mailinglist.c @@ -0,0 +1,77 @@ +#include "config.h" + +/* +*/ + +#include	"sqwebmail.h" +#include	"mailinglist.h" +#include	"rfc822/rfc822.h" +#include	<stdio.h> +#include	<string.h> +#include	<ctype.h> +#include	<stdlib.h> +#include	<unistd.h> +#include	<sys/types.h> +#include	<sys/stat.h> + +#define	MAILINGLISTS	"sqwebmail-mailinglists" +#define	MAILINGLISTSTMP	"sqwebmail-mailinglists.tmp" + +char *getmailinglists() +{ +	FILE *fp=fopen(MAILINGLISTS, "r"); +	struct stat stat_buf; +	char *buf; +	int l; + +	if (!fp) +		return (0); + +	if (fstat(fileno(fp), &stat_buf) != 0 || +	    (buf=malloc(stat_buf.st_size+1)) == NULL) +	{ +		fclose(fp); +		return (0); +	} + +	l=fread(buf, 1, stat_buf.st_size, fp); +	fclose(fp); + +	if (l < 0) +		l=0; +	buf[l]=0; +	return (buf); +} + +void savemailinglists(const char *p) +{ +	FILE *fp; +	int lastc; + +	if ((fp=fopen(MAILINGLISTSTMP, "w")) == NULL) +		return; + +	for (lastc='\n'; *p; p++) +	{ +		if (isspace((int)(unsigned char)*p) && *p != '\n') +			continue; + +		if (*p == '\n' && lastc == '\n') +			continue; + +		putc(*p, fp); +		lastc=*p; +	} +	 +	fprintf(fp, "%s", p); +	fflush(fp); +	if (ferror(fp)) +	{ +		fclose(fp); +		unlink(MAILINGLISTSTMP); +		return; +	} +	fclose(fp); +	rename (MAILINGLISTSTMP, MAILINGLISTS); +} + | 
