1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
}
|