1 /*
2 ** Copyright 1998 - 2002 Double Precision, Inc.
3 ** See COPYING for distribution information.
4 */
5 
6 #include	"config.h"
7 #include	<stdlib.h>
8 #include	<string.h>
9 #include	<stdio.h>
10 #include	<ctype.h>
11 #include	"maildirrequota.h"
12 
13 
maildir_requota(const char * oldname,unsigned long s)14 char *maildir_requota(const char *oldname, unsigned long s)
15 {
16 char	buf[40];
17 char	*p;
18 const char *q;
19 
20 	sprintf(buf, ",S=%lu", s);
21 
22 	if ((p=malloc(strlen(oldname)+strlen(buf)+1)) == 0)	return (0);
23 
24 	if ((q=strrchr(oldname, '/')) == 0)	q=oldname;
25 	while (*q)
26 	{
27 		if ((*q == ',' && q[1] == 'S' && q[2] == '=') || *q == MDIRSEP[0])
28 		{
29 			memcpy(p, oldname, q-oldname);
30 			strcpy(p + (q-oldname), buf);
31 
32 			if (*q == ',')	q += 3;
33 
34 			for ( ; isdigit((int)(unsigned char)*q); q++)
35 				;
36 			strcat(p, q);
37 			return (p);
38 		}
39 		++q;
40 	}
41 	return (strcat(strcpy(p, oldname), buf));
42 }
43