Commit 3211c993 3211c99378cb748df3f7e9334adeceadf0ee4aff by Alain Magloire

not implemented.

1 parent d2ff2875
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <errno.h>
19 #include <mailbox0.h>
20 #include <registrar0.h>
21
22
23 static int mailbox_imap_create (mailbox_t *mbox, const char *name);
24 static void mailbox_imap_destroy (mailbox_t *mbox);
25
26 struct mailbox_registrar _mailbox_imap_registrar =
27 {
28 "IMAP4",
29 mailbox_imap_create, mailbox_imap_destroy
30 };
31
32 void
33 mailbox_imap_destroy (mailbox_t *mbox)
34 {
35 (void)mbox;
36 return;
37 }
38
39 int
40 mailbox_imap_create (mailbox_t *mbox, const char *name)
41 {
42 (void)mbox; (void)name;
43 return ENOSYS;
44 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <errno.h>
19 #include <mailbox0.h>
20 #include <registrar0.h>
21
22 static int mailbox_maildir_create (mailbox_t *mbox, const char *name);
23 static void mailbox_maildir_destroy (mailbox_t *mbox);
24
25 struct mailbox_registrar _mailbox_maildir_registrar =
26 {
27 "MAILDIR",
28 mailbox_maildir_create, mailbox_maildir_destroy
29 };
30
31 int
32 mailbox_maildir_create (mailbox_t *mbox, const char *name)
33 {
34 (void)mbox; (void)name;
35 return ENOSYS;
36 }
37
38 void
39 mailbox_maildir_destroy (mailbox_t *mbox)
40 {
41 (void)mbox;
42 return;
43 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 * Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Library Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <dirent.h>
20 #include <errno.h>
21 #include <string.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <ctype.h>
27
28 #include <mailbox0.h>
29 #include <registrar0.h>
30
31 static int mailbox_mh_create (mailbox_t *pmbox, const char *name);
32 static void mailbox_mh_destroy (mailbox_t *pmbox);
33
34 struct mailbox_registrar _mailbox_mh_registrar =
35 {
36 "MH",
37 mailbox_mh_create, mailbox_mh_destroy
38 };
39
40 typedef struct _mh_data
41 {
42 time_t mtime; /* used for checking if mailbox was updated */
43 } mh_data;
44
45 static int mh_open (mailbox_t mbox, int flags);
46 static int mh_close (mailbox_t mbox);
47 static int mh_scan (mailbox_t mbox, size_t msgno, size_t *msgs);
48 static int mh_sequence(const char *name);
49
50 static int
51 mailbox_mh_create (mailbox_t *pmbox, const char *name)
52 {
53 mailbox_t mbox;
54 mh_data *data;
55
56 mbox = malloc(sizeof(*mbox));
57 data = malloc(sizeof(mh_data));
58 mbox->name = malloc(strlen(name) + 1);
59 strcpy(mbox->name, name);
60 mbox->data = data;
61 mbox->_create = mailbox_mh_create;
62 mbox->_destroy = mailbox_mh_destroy;
63 mbox->_open = mh_open;
64 mbox->_close = mh_close;
65 mbox->_scan = mh_scan;
66 *pmbox = mbox;
67
68 return 0;
69 }
70
71 static void
72 mailbox_mh_destroy (mailbox_t *pmbox)
73 {
74 free((*pmbox)->data);
75 free((*pmbox)->name);
76 free(*pmbox);
77 pmbox = NULL;
78 }
79
80 /* FIXME: handle create once the design is ready */
81
82 /* mh_scan actually does all the dirty work */
83 static int
84 mh_open (mailbox_t mbox, int flags)
85 {
86 struct stat st;
87 mh_data *data;
88
89 (void) flags;
90 if (stat(mbox->name, &st) == -1)
91 return errno;
92
93 if (! S_ISDIR(st.st_mode))
94 return EINVAL; /* mailbox is not a directory, thus it is also not MH */
95
96 data = mbox->data;
97 /* FIXME: does mtime change when the dir has a new file added? */
98 data->mtime = st.st_mtime;
99
100 return 0; /* everything is fine */
101 }
102
103 static int
104 mh_close (mailbox_t mbox)
105 {
106 mh_data *data;
107
108 data = mbox->data;
109
110 /* FIXME: implementation */
111 return 0;
112 }
113
114 static int
115 mh_scan (mailbox_t mbox, size_t msgno, size_t *msgs)
116 {
117 struct stat st;
118 DIR *maildir;
119 struct dirent *entry;
120 mh_data *data;
121 unsigned int count = 0;
122 int parse_sequence_file = 0;
123
124 (void)msgno;
125
126 data = mbox->data;
127
128 maildir = opendir(mbox->name);
129
130 while((entry = readdir(maildir)) != NULL) {
131 if(strcmp(".", entry->d_name) == 0 ||
132 strcmp("..", entry->d_name) == 0)
133 continue;
134 /* FIXME: handle this MH extension */
135 if(entry->d_name[0] == '+')
136 continue;
137 /* FIXME: decide what to do with messages marked for removal */
138 if(entry->d_name[0] == ',')
139 continue;
140 if(entry->d_name[0] == '.') {
141 if(strcmp(".mh_sequences", entry->d_name))
142 continue; /* spurious file beginning w/ '.' */
143 else { /* MH info in .mh_sequences */
144 /* FIXME: parse this file */
145 parse_sequence_file = 1;
146 }
147 }
148 if(mh_sequence(entry->d_name)) {
149 /* FIXME: parse file */
150 count++;
151 }
152 }
153 closedir(maildir);
154
155 if(parse_sequence_file && count) {
156 FILE *fp;
157 char *path = malloc(strlen(mbox->name) + strlen(".mh_sequences") + 2);
158 sprintf(path, "%s/.mh_sequences", mbox->name);
159 fp = fopen(path, "r");
160 while(!feof(fp)) {
161 /* FIXME: parse the contents */
162 }
163 fclose(fp);
164 free(path);
165 }
166
167 stat(mbox->name, &st);
168 data->mtime = st.st_mtime;
169
170 if(msgs)
171 *msgs = count;
172 return 0;
173 }
174
175 /*
176 * Local atoi()
177 * created this to guarantee that name is only digits, normal atoi allows
178 * whitespace
179 */
180 static int
181 mh_sequence(const char *name)
182 {
183 const char *sequence;
184 int i;
185
186 for(i = 0, sequence = name; *sequence; sequence++) {
187 if(!isdigit(*sequence))
188 return 0;
189 i *= 10;
190 i += (*sequence - '0');
191 }
192 return i;
193 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <errno.h>
19
20 #include <mailbox0.h>
21 #include <registrar0.h>
22
23 static int mailbox_mmdf_create (mailbox_t *mbox, const char *name);
24 static void mailbox_mmdf_destroy (mailbox_t *mbox);
25
26 struct mailbox_registrar _mailbox_mmdf_registrar =
27 {
28 "MMDF",
29 mailbox_mmdf_create, mailbox_mmdf_destroy
30 };
31
32 static int
33 mailbox_mmdf_create (mailbox_t *mbox, const char *name)
34 {
35 (void)mbox; (void)name;
36 return ENOSYS;
37 }
38
39 static void
40 mailbox_mmdf_destroy (mailbox_t *mbox)
41 {
42 (void)mbox;
43 return;
44 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20 #include <errno.h>
21
22 static int url_imap_create (url_t *purl, const char *name);
23 static void url_imap_destroy (url_t *purl);
24
25 struct url_registrar _url_imap_registrar =
26 {
27 "imap://",
28 url_imap_create, url_imap_destroy
29 };
30
31 static void
32 url_imap_destroy (url_t *purl)
33 {
34 (void)purl;
35 return;
36 }
37
38 static int
39 url_imap_create (url_t *purl, const char *name)
40 {
41 (void)purl; (void)name;
42 return ENOSYS;
43 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20 #include <errno.h>
21
22 static int url_mailto_create (url_t *purl, const char *name);
23 static void url_mailto_destroy (url_t *purl);
24
25 struct url_registrar _url_mailto_registrar =
26 {
27 "mailto:",
28 url_mailto_create, url_mailto_destroy
29 };
30
31 static void
32 url_mailto_destroy (url_t *purl)
33 {
34 (void)purl;
35 return;
36 }
37
38 static int
39 url_mailto_create (url_t *purl, const char *name)
40 {
41 (void)purl; (void)name;
42 return ENOSYS;
43 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_maildir_destroy (url_t *purl);
26 static int url_maildir_create (url_t *purl, const char *name);
27
28 struct url_registrar _url_maildir_registrar =
29 {
30 "maildir:",
31 url_maildir_create, url_maildir_destroy
32 };
33
34 static void
35 url_maildir_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MAILDIR URL
49 maildir:
50 */
51 static int
52 url_maildir_create (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_maildir_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < (scheme_len + 1) /* (scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return EINVAL;
68
69 /* TYPE */
70 url->_create = ureg->_create;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_mh_destroy (url_t *purl);
26 static int url_mh_create (url_t *purl, const char *name);
27
28 struct url_registrar _url_mh_registrar =
29 {
30 "mh:",
31 url_mh_create, url_mh_destroy
32 };
33
34 static void
35 url_mh_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MH URL
49 mh:
50 */
51 static int
52 url_mh_create (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_mh_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < (scheme_len + 1) /* (scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_create = ureg->_create;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_mmdf_destroy (url_t *purl);
26 static int url_mmdf_create (url_t *purl, const char *name);
27
28 struct url_registrar _url_mmdf_registrar =
29 {
30 "mmdf:",
31 url_mmdf_create, url_mmdf_destroy
32 };
33
34 static void
35 url_mmdf_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MMDF URL
49 mmdf:
50 */
51 static int
52 url_mmdf_create (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_mmdf_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < 8 /* 7(scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_create = ureg->_create;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <mailutils/registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_unix_destroy (url_t *purl);
26 static int url_unix_create (url_t *purl, const char *name);
27
28 struct url_registrar _url_unix_registrar =
29 {
30 "unix:",
31 url_unix_create, url_unix_destroy
32 };
33
34 static void
35 url_unix_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 UNIX Mbox
49 unix:/path
50 */
51 static int
52 url_unix_create (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_unix_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < scheme_len + 1 /* 7(scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_create = ureg->_create;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }