Cross Reference: /dovecot/src/lib-storage/mail.c
mail.c revision 45312f52ff3a3d4c137447be4c7556500c2f8bf2
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen#include "lib.h"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen#include "ioloop.h"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen#include "hostpid.h"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen#include "mail-storage-private.h"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen#include <time.h>
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenstruct mail *mail_alloc(struct mailbox_transaction_context *t,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen enum mail_fetch_field wanted_fields,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen{
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen return t->box->v.mail_alloc(t, wanted_fields, wanted_headers);
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen}
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen
void mail_free(struct mail **mail)
{
struct mail_private *p = (struct mail_private *)*mail;
p->v.free(*mail);
*mail = NULL;
}
void mail_set_seq(struct mail *mail, uint32_t seq)
{
struct mail_private *p = (struct mail_private *)mail;
p->v.set_seq(mail, seq);
}
bool mail_set_uid(struct mail *mail, uint32_t uid)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.set_uid(mail, uid);
}
enum mail_flags mail_get_flags(struct mail *mail)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_flags(mail);
}
uint64_t mail_get_modseq(struct mail *mail)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_modseq(mail);
}
const char *const *mail_get_keywords(struct mail *mail)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_keywords(mail);
}
const ARRAY_TYPE(keyword_indexes) *mail_get_keyword_indexes(struct mail *mail)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_keyword_indexes(mail);
}
int mail_get_parts(struct mail *mail, const struct message_part **parts_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_parts(mail, parts_r);
}
int mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r)
{
struct mail_private *p = (struct mail_private *)mail;
int tz;
if (timezone_r == NULL)
timezone_r = &tz;
return p->v.get_date(mail, date_r, timezone_r);
}
int mail_get_received_date(struct mail *mail, time_t *date_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_received_date(mail, date_r);
}
int mail_get_save_date(struct mail *mail, time_t *date_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_save_date(mail, date_r);
}
int mail_get_virtual_size(struct mail *mail, uoff_t *size_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_virtual_size(mail, size_r);
}
int mail_get_physical_size(struct mail *mail, uoff_t *size_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_physical_size(mail, size_r);
}
int mail_get_first_header(struct mail *mail, const char *field,
const char **value_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_first_header(mail, field, FALSE, value_r);
}
int mail_get_first_header_utf8(struct mail *mail, const char *field,
const char **value_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_first_header(mail, field, TRUE, value_r);
}
int mail_get_headers(struct mail *mail, const char *field,
const char *const **value_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_headers(mail, field, FALSE, value_r);
}
int mail_get_headers_utf8(struct mail *mail, const char *field,
const char *const **value_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_headers(mail, field, TRUE, value_r);
}
int mail_get_header_stream(struct mail *mail,
struct mailbox_header_lookup_ctx *headers,
struct istream **stream_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_header_stream(mail, headers, stream_r);
}
int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
struct message_size *body_size, struct istream **stream_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_stream(mail, hdr_size, body_size, stream_r);
}
int mail_get_special(struct mail *mail, enum mail_fetch_field field,
const char **value_r)
{
struct mail_private *p = (struct mail_private *)mail;
return p->v.get_special(mail, field, value_r);
}
void mail_update_flags(struct mail *mail, enum modify_type modify_type,
enum mail_flags flags)
{
struct mail_private *p = (struct mail_private *)mail;
p->v.update_flags(mail, modify_type, flags);
}
void mail_update_keywords(struct mail *mail, enum modify_type modify_type,
struct mail_keywords *keywords)
{
struct mail_private *p = (struct mail_private *)mail;
p->v.update_keywords(mail, modify_type, keywords);
}
void mail_expunge(struct mail *mail)
{
struct mail_private *p = (struct mail_private *)mail;
p->v.expunge(mail);
}
void mail_set_expunged(struct mail *mail)
{
mail_storage_set_error(mail->box->storage, MAIL_ERROR_EXPUNGED,
"Message was expunged");
mail->expunged = TRUE;
}
void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
{
struct mail_private *p = (struct mail_private *)mail;
p->v.set_cache_corrupted(mail, field);
}
const char *mail_generate_guid_string(void)
{
static struct timespec ts = { 0, 0 };
static unsigned int pid = 0;
/* we'll use the current time in nanoseconds as the initial 64bit
counter. */
if (ts.tv_sec == 0) {
if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
i_fatal("clock_gettime() failed: %m");
pid = getpid();
} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
ts.tv_nsec++;
} else {
ts.tv_sec++;
ts.tv_nsec = 0;
}
return t_strdup_printf("%04x%04lx%04x%s",
(unsigned int)ts.tv_nsec,
(unsigned long)ts.tv_sec,
pid, my_hostname);
}