folder.c
2.51 KB
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
91
92
93
94
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/errno.h>
#include <mailutils/error.h>
#include <mailutils/url.h>
#include <mailbox0.h>
#include <url0.h>
#include <folder0.h>
#include <registrar0.h>
#define MU_REMOTE_MBOX_PREFIX "remote+"
#define MU_REMOTE_MBOX_PREFIX_LEN (sizeof (MU_REMOTE_MBOX_PREFIX) - 1)
extern int remote_mbox_init (mu_mailbox_t mailbox);
int
remote_url_init (mu_url_t url)
{
const char *name = mu_url_to_string (url);
const char *p;
size_t len = strlen (name);
int rc;
if (!name)
return 0;
/* reject the obvious */
if (name == NULL
|| len < MU_REMOTE_MBOX_PREFIX_LEN
|| strncmp (MU_REMOTE_MBOX_PREFIX, name, MU_REMOTE_MBOX_PREFIX_LEN) != 0)
return EINVAL;
rc = mu_registrar_lookup (name + MU_REMOTE_MBOX_PREFIX_LEN, 0, NULL, NULL);
if (rc)
return rc;
p = strchr (name, ':');
if (!p)
return EINVAL;
p++;
len = p - name;
url->scheme = malloc (len + 1);
if (!url->scheme)
return ENOMEM;
memcpy (url->scheme, name, len);
url->scheme[len] = 0;
return 0;
}
static int
remote_folder_init (mu_folder_t folder MU_ARG_UNUSED)
{
return 0;
}
static struct _mu_record _remote_mbox_record =
{
MU_REMOTE_MBOX_PRIO,
MU_REMOTE_MBOX_PREFIX,
remote_url_init, /* Mailbox init. */
remote_mbox_init, /* Mailbox init. */
NULL, /* Mailer init. */
remote_folder_init, /* Folder init. */
NULL, /* No need for back pointer. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
mu_record_t mu_remote_mbox_record = &_remote_mbox_record;