-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maildir.c
142 lines (111 loc) 路 2.22 KB
/
maildir.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Copyright (c) 2016 Richard Russon <rich@flatcap.org>
* Released under the GPLv3 -- see LICENSE.md for details */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "email.h"
#include "folder.h"
#include "maildir.h"
#include "plugin.h"
#include "source.h"
#include "view.h"
void
maildir_destroy (MAILDIR *m)
{
if (!m) {
return;
}
// Nothing MAILDIR-specific to release
source_destroy (&m->source); // Destroy parent
}
MAILDIR *
maildir_create (MAILDIR *m)
{
if (!m) {
m = calloc (1, sizeof (MAILDIR));
if (!m) {
return NULL;
}
}
source_create (&m->source); // Construct parent
OBJECT *o = &m->source.container.object;
o->type = MAGIC_MAILDIR;
o->name = strdup ("maildir");
o->destroy = (object_destroy_fn) maildir_destroy;
return m;
}
static SOURCE *
maildir_init (void)
{
MAILDIR *ms = maildir_create (NULL);
if (!ms) {
return NULL;
}
return &ms->source;
}
static int
maildir_config_item (const char *name)
{
if (!name) {
return 0;
}
if ((name[0] >= 'i') && (name[0] <= 'l')) {
// printf ("maildir config: %s\n", name);
return 1;
}
return 0;
}
static void
maildir_connect (SOURCE *s)
{
FOLDER *f1 = folder_create (NULL);
FOLDER *f2 = folder_create (NULL);
FOLDER *f3 = folder_create (NULL);
if (!f1 || !f2 || !f3) {
printf ("maildir_connect: folder_create failed\n");
return;
}
f1->container.object.name = strdup ("boys");
f2->container.object.name = strdup ("trees");
f3->container.object.name = strdup ("fish");
const char *names[] = { "adam", "barry", "charlie", "ash", "beech", "angel", "beluga", NULL };
int i;
EMAIL *e;
for (i = 0; names[i]; i++) {
e = email_create (NULL);
if (!e) {
printf ("imap_connect: email_create failed\n");
return;
}
e->item.object.name = strdup (names[i]);
if (i < 3) {
add_child (f1, e);
} else if (i < 5) {
add_child (f2, e);
} else {
add_child (f3, e);
}
release (e);
}
add_child (f1, f2);
add_child (f1, f3);
release (f2);
release (f3);
add_child (s, f1);
release (f1);
}
static void
maildir_disconnect (SOURCE *src)
{
if (!src) {
return;
}
}
PLUGIN maildir_plugin = {
MAGIC_MAILDIR,
"maildir",
maildir_init,
maildir_config_item,
maildir_connect,
maildir_disconnect
};