Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/mbox/mbox-save.c @ 4681:cc110cb8c56b HEAD
Filter out "From " lines from headers. There's no reason they should exist
in there and they'll cause problems.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 15 Oct 2006 18:42:58 +0300 |
parents | 8b9933470cf8 |
children | 5b4c9b20eba0 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "lib.h" | |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
4 #include "ioloop.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3464
diff
changeset
|
5 #include "array.h" |
0 | 6 #include "hostpid.h" |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
7 #include "istream.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
674
diff
changeset
|
8 #include "ostream.h" |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
9 #include "str.h" |
29
e9375147c0cb
Added write_full() which is a simple wrapper around write() meant for
Timo Sirainen <tss@iki.fi>
parents:
22
diff
changeset
|
10 #include "write-full.h" |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
11 #include "istream-header-filter.h" |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
12 #include "ostream-crlf.h" |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
13 #include "message-parser.h" |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
14 #include "index-mail.h" |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
15 #include "mbox-storage.h" |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
16 #include "mbox-file.h" |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
17 #include "mbox-from.h" |
0 | 18 #include "mbox-lock.h" |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
19 #include "mbox-md5.h" |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
20 #include "mbox-sync-private.h" |
0 | 21 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
22 #include <stddef.h> |
0 | 23 #include <stdlib.h> |
24 #include <unistd.h> | |
25 #include <fcntl.h> | |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
26 #include <sys/stat.h> |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
27 #include <netdb.h> |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
28 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
29 struct mbox_save_context { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
30 struct mail_save_context ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
31 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
32 struct mbox_mailbox *mbox; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
33 struct mail_index_transaction *trans; |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
34 struct mail *mail; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
35 uoff_t append_offset, mail_offset; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
36 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
37 string_t *headers; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
38 size_t space_end_idx; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
39 uint32_t seq, next_uid; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
40 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
41 struct istream *input; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
42 struct ostream *output, *body_output; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
43 uoff_t extra_hdr_offset, eoh_offset, eoh_input_offset; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
44 char last_char; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
45 |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
46 struct mbox_md5_context *mbox_md5_ctx; |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
47 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
48 unsigned int synced:1; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
49 unsigned int failed:1; |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
50 unsigned int finished:1; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
51 }; |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
52 |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
53 static char my_hostdomain[256] = ""; |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
54 |
2486 | 55 static void write_error(struct mbox_save_context *ctx, int error) |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
56 { |
2486 | 57 if (ENOSPACE(error)) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
58 mail_storage_set_error(STORAGE(ctx->mbox->storage), |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
59 "Not enough disk space"); |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
60 } else { |
2486 | 61 errno = error; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
62 mbox_set_syscall_error(ctx->mbox, "write()"); |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
63 } |
3348
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
64 |
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
65 ctx->failed = TRUE; |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
66 } |
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
67 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
68 static int mbox_seek_to_end(struct mbox_save_context *ctx, uoff_t *offset) |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
69 { |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
70 struct stat st; |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
71 char ch; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
72 int fd; |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
73 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
74 if (ctx->mbox->mbox_writeonly) { |
2986
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
75 *offset = 0; |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
76 return 0; |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
77 } |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
78 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
79 fd = ctx->mbox->mbox_fd; |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
80 if (fstat(fd, &st) < 0) |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
81 return mbox_set_syscall_error(ctx->mbox, "fstat()"); |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
82 |
1039
793f05a7e50e
signed/unsigned/const pointer fixes
Timo Sirainen <tss@iki.fi>
parents:
1030
diff
changeset
|
83 *offset = (uoff_t)st.st_size; |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
84 if (st.st_size == 0) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
85 return 0; |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
86 |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
87 if (lseek(fd, st.st_size-1, SEEK_SET) < 0) |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
88 return mbox_set_syscall_error(ctx->mbox, "lseek()"); |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
89 |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
90 if (read(fd, &ch, 1) != 1) |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
91 return mbox_set_syscall_error(ctx->mbox, "read()"); |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
92 |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
93 if (ch != '\n') { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
94 if (write_full(fd, "\n", 1) < 0) { |
2486 | 95 write_error(ctx, errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
96 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
97 } |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
98 *offset += 1; |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
99 } |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
100 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
101 return 0; |
223
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
102 } |
ca6967899c05
More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
103 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
104 static int mbox_append_lf(struct mbox_save_context *ctx) |
266
757c32a1920d
expunging last message from mbox duplicated the whole file. appending mail
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
105 { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
106 if (o_stream_send(ctx->output, "\n", 1) < 0) { |
2486 | 107 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
108 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
109 } |
266
757c32a1920d
expunging last message from mbox duplicated the whole file. appending mail
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
110 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
111 return 0; |
266
757c32a1920d
expunging last message from mbox duplicated the whole file. appending mail
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
112 } |
757c32a1920d
expunging last message from mbox duplicated the whole file. appending mail
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
113 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
114 static int write_from_line(struct mbox_save_context *ctx, time_t received_date, |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
115 const char *from_envelope) |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
116 { |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
117 const char *line, *name; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
118 int ret; |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
119 |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
120 if (*my_hostdomain == '\0') { |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
121 struct hostent *hent; |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
122 |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
123 hent = gethostbyname(my_hostname); |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
124 |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
125 name = hent != NULL ? hent->h_name : NULL; |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
126 if (name == NULL) { |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
127 /* failed, use just the hostname */ |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
128 name = my_hostname; |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
129 } |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
130 |
809
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
131 strocpy(my_hostdomain, name, sizeof(my_hostdomain)); |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
132 } |
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
133 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
134 t_push(); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
135 if (from_envelope == NULL) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
136 from_envelope = |
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
137 t_strconcat(INDEX_STORAGE(ctx->mbox->storage)->user, |
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
138 "@", my_hostdomain, NULL); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
139 } |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
140 |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
472
diff
changeset
|
141 /* save in local timezone, no matter what it was given with */ |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
142 line = mbox_from_create(from_envelope, received_date); |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
143 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
144 if ((ret = o_stream_send_str(ctx->output, line)) < 0) |
2486 | 145 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
146 t_pop(); |
314
d2a305fa0ec2
mbox ignored message flags for APPEND.
Timo Sirainen <tss@iki.fi>
parents:
305
diff
changeset
|
147 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
148 return ret; |
314
d2a305fa0ec2
mbox ignored message flags for APPEND.
Timo Sirainen <tss@iki.fi>
parents:
305
diff
changeset
|
149 } |
d2a305fa0ec2
mbox ignored message flags for APPEND.
Timo Sirainen <tss@iki.fi>
parents:
305
diff
changeset
|
150 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
151 static int mbox_write_content_length(struct mbox_save_context *ctx) |
314
d2a305fa0ec2
mbox ignored message flags for APPEND.
Timo Sirainen <tss@iki.fi>
parents:
305
diff
changeset
|
152 { |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
153 uoff_t end_offset; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
154 const char *str; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
155 size_t len; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
156 int ret = 0; |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
157 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
158 if (ctx->mbox->mbox_writeonly) { |
2986
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
159 /* we can't seek, don't set Content-Length */ |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
160 return 0; |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
161 } |
51a05fd00324
Named pipes are now treated as write-only mboxes.
Timo Sirainen <tss@iki.fi>
parents:
2978
diff
changeset
|
162 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
163 end_offset = ctx->output->offset; |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
164 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
165 /* write Content-Length headers */ |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
166 t_push(); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
167 str = t_strdup_printf("\nContent-Length: %s", |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
168 dec2str(end_offset - ctx->eoh_offset)); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
169 len = strlen(str); |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
170 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
171 if (o_stream_seek(ctx->output, ctx->extra_hdr_offset + |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
172 ctx->space_end_idx - len) < 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
173 mbox_set_syscall_error(ctx->mbox, "o_stream_seek()"); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
174 ret = -1; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
175 } else if (o_stream_send(ctx->output, str, len) < 0) { |
2486 | 176 write_error(ctx, ctx->output->stream_errno); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
177 ret = -1; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
178 } else { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
179 if (o_stream_seek(ctx->output, end_offset) < 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
180 mbox_set_syscall_error(ctx->mbox, "o_stream_seek()"); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
181 ret = -1; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
182 } |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
183 } |
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
184 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
185 t_pop(); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
186 return ret; |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
187 } |
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
188 |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
189 static void mbox_save_init_sync(struct mbox_transaction_context *t) |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
190 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
191 struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
192 struct mbox_save_context *ctx = t->save_ctx; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
193 const struct mail_index_header *hdr; |
3221
af8fc972fe95
If want_mail = TRUE for mbox_save_init() and we sync the mbox, we'll have to
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
194 struct mail_index_view *view; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
195 |
3221
af8fc972fe95
If want_mail = TRUE for mbox_save_init() and we sync the mbox, we'll have to
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
196 /* open a new view to get the header. this is required if we just |
af8fc972fe95
If want_mail = TRUE for mbox_save_init() and we sync the mbox, we'll have to
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
197 synced the mailbox so we can get updated next_uid. */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
198 view = mail_index_view_open(mbox->ibox.index); |
3221
af8fc972fe95
If want_mail = TRUE for mbox_save_init() and we sync the mbox, we'll have to
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
199 hdr = mail_index_get_header(view); |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
200 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
201 ctx->next_uid = hdr->next_uid; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
202 ctx->synced = TRUE; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
203 t->mbox_modified = TRUE; |
3221
af8fc972fe95
If want_mail = TRUE for mbox_save_init() and we sync the mbox, we'll have to
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
204 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
205 mail_index_view_close(&view); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
206 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
207 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
208 static void status_flags_append(string_t *str, enum mail_flags flags, |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
209 const struct mbox_flag_type *flags_list) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
210 { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
211 int i; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
212 |
3250
3b820e59610e
Recent flag handling cleanups. Added some comments.
Timo Sirainen <tss@iki.fi>
parents:
3245
diff
changeset
|
213 flags ^= MBOX_NONRECENT_KLUDGE; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
214 for (i = 0; flags_list[i].chr != 0; i++) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
215 if ((flags & flags_list[i].flag) != 0) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
216 str_append_c(str, flags_list[i].chr); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
217 } |
3250
3b820e59610e
Recent flag handling cleanups. Added some comments.
Timo Sirainen <tss@iki.fi>
parents:
3245
diff
changeset
|
218 flags ^= MBOX_NONRECENT_KLUDGE; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
219 } |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
220 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
221 static void mbox_save_append_flag_headers(string_t *str, enum mail_flags flags) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
222 { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
223 if ((flags & STATUS_FLAGS_MASK) != 0) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
224 str_append(str, "Status: "); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
225 status_flags_append(str, flags, mbox_status_flags); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
226 str_append_c(str, '\n'); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
227 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
228 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
229 if ((flags & XSTATUS_FLAGS_MASK) != 0) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
230 str_append(str, "X-Status: "); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
231 status_flags_append(str, flags, mbox_xstatus_flags); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
232 str_append_c(str, '\n'); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
233 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
234 } |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
235 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2986
diff
changeset
|
236 static void |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2986
diff
changeset
|
237 mbox_save_append_keyword_headers(struct mbox_save_context *ctx, |
3086 | 238 struct mail_keywords *keywords) |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
239 { |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2261
diff
changeset
|
240 unsigned char space[MBOX_HEADER_PADDING+1 + |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
241 sizeof("Content-Length: \n")-1 + MAX_INT_STRLEN]; |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4412
diff
changeset
|
242 const ARRAY_TYPE(keywords) *keyword_names_list; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
243 const char *const *keyword_names; |
3262
f1134d265a9d
Don't crash while saving message if keywords aren't given..
Timo Sirainen <tss@iki.fi>
parents:
3260
diff
changeset
|
244 unsigned int i, count, keyword_names_count; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
245 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
246 keyword_names_list = mail_index_get_keywords(ctx->mbox->ibox.index); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
247 keyword_names = array_get(keyword_names_list, &keyword_names_count); |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
248 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
249 str_append(ctx->headers, "X-Keywords:"); |
3262
f1134d265a9d
Don't crash while saving message if keywords aren't given..
Timo Sirainen <tss@iki.fi>
parents:
3260
diff
changeset
|
250 count = keywords == NULL ? 0 : keywords->count; |
f1134d265a9d
Don't crash while saving message if keywords aren't given..
Timo Sirainen <tss@iki.fi>
parents:
3260
diff
changeset
|
251 for (i = 0; i < count; i++) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
252 i_assert(keywords->idx[i] < keyword_names_count); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
253 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
254 str_append_c(ctx->headers, ' '); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
255 str_append(ctx->headers, keyword_names[keywords->idx[i]]); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3250
diff
changeset
|
256 } |
1209
539b7336b68a
mbox: strip some headers when saving message. also always set Content-Length
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
257 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
258 memset(space, ' ', sizeof(space)); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
259 str_append_n(ctx->headers, space, sizeof(space)); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
260 ctx->space_end_idx = str_len(ctx->headers); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
261 str_append_c(ctx->headers, '\n'); |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
262 } |
0 | 263 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
264 static int |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
265 mbox_save_init_file(struct mbox_save_context *ctx, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3662
diff
changeset
|
266 struct mbox_transaction_context *t, bool want_mail) |
0 | 267 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
268 struct mbox_mailbox *mbox = ctx->mbox; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
269 int ret; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
270 |
4193
a47df521d4fa
If mailbox was opened with readonly-flag, don't really force it. Fixes
Timo Sirainen <tss@iki.fi>
parents:
4070
diff
changeset
|
271 if (ctx->mbox->mbox_readonly) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
272 mail_storage_set_error(STORAGE(ctx->mbox->storage), |
3245
6491dab63e54
Added input stream parameter to mailbox_open(). With mbox it now allows
Timo Sirainen <tss@iki.fi>
parents:
3221
diff
changeset
|
273 "Read-only mbox"); |
6491dab63e54
Added input stream parameter to mailbox_open(). With mbox it now allows
Timo Sirainen <tss@iki.fi>
parents:
3221
diff
changeset
|
274 return -1; |
6491dab63e54
Added input stream parameter to mailbox_open(). With mbox it now allows
Timo Sirainen <tss@iki.fi>
parents:
3221
diff
changeset
|
275 } |
6491dab63e54
Added input stream parameter to mailbox_open(). With mbox it now allows
Timo Sirainen <tss@iki.fi>
parents:
3221
diff
changeset
|
276 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
277 if (ctx->append_offset == (uoff_t)-1) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
278 /* first appended mail in this transaction */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
279 if (mbox->mbox_lock_type != F_WRLCK) { |
3662
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
280 if (mbox->mbox_lock_type == F_RDLCK) { |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
281 /* FIXME: we shouldn't fail here. it's just |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
282 a locking issue that should be possible to |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
283 fix.. */ |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
284 mail_storage_set_error( |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
285 STORAGE(ctx->mbox->storage), |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
286 "Can't copy mails inside same mailbox"); |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
287 return -1; |
247501e81026
Instead of crashing when trying to copy mails within same mailbox, give an
Timo Sirainen <tss@iki.fi>
parents:
3565
diff
changeset
|
288 } |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
289 if (mbox_lock(mbox, F_WRLCK, &t->mbox_lock_id) <= 0) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
290 return -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
291 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
292 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
293 if (mbox->mbox_fd == -1) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
294 if (mbox_file_open(mbox) < 0) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
295 return -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
296 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
297 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
298 if (!want_mail) { |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
299 /* assign UIDs only if mbox doesn't require syncing */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
300 ret = mbox_sync_has_changed(mbox, TRUE); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
301 if (ret < 0) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
302 return -1; |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
303 if (ret == 0) |
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
304 mbox_save_init_sync(t); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
305 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
306 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
307 if (mbox_seek_to_end(ctx, &ctx->append_offset) < 0) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
308 return -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
309 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
310 ctx->output = o_stream_create_file(mbox->mbox_fd, default_pool, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
311 0, FALSE); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
312 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
313 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
314 if (!ctx->synced && want_mail) { |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
315 /* we'll need to assign UID for the mail immediately. */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
316 if (mbox_sync(mbox, 0) < 0) |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
317 return -1; |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
318 mbox_save_init_sync(t); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
319 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
320 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
321 return 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
322 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
323 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
324 static void save_header_callback(struct message_header_line *hdr, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3662
diff
changeset
|
325 bool *matched, void *context) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
326 { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
327 struct mbox_save_context *ctx = context; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
328 |
4681
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
329 if (hdr != NULL) { |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
330 if (strncmp(hdr->name, "From ", 5) == 0) { |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
331 /* we can't allow From_-lines in headers. there's no |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
332 legitimate reason for allowing them in any case, |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
333 so just drop them. */ |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
334 *matched = TRUE; |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
335 return; |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
336 } |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
337 |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
338 if (!*matched && ctx->mbox_md5_ctx != NULL) |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
339 mbox_md5_continue(ctx->mbox_md5_ctx, hdr); |
cc110cb8c56b
Filter out "From " lines from headers. There's no reason they should exist
Timo Sirainen <tss@iki.fi>
parents:
4562
diff
changeset
|
340 } |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
341 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
342 if ((hdr == NULL && ctx->eoh_input_offset == (uoff_t)-1) || |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
343 (hdr != NULL && hdr->eoh)) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
344 ctx->eoh_input_offset = ctx->input->v_offset; |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
345 |
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
346 if (ctx->mail != NULL) { |
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
347 index_mail_parse_header(NULL, hdr, |
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
348 (struct index_mail *)ctx->mail); |
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
349 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
350 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
351 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
352 int mbox_save_init(struct mailbox_transaction_context *_t, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
353 enum mail_flags flags, struct mail_keywords *keywords, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
354 time_t received_date, int timezone_offset __attr_unused__, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
355 const char *from_envelope, struct istream *input, |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
356 struct mail *dest_mail, struct mail_save_context **ctx_r) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
357 { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
358 struct mbox_transaction_context *t = |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
359 (struct mbox_transaction_context *)_t; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
360 struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
361 struct mbox_save_context *ctx = t->save_ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
362 enum mail_flags save_flags; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
363 uint64_t offset; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
364 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
365 i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
366 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
367 /* FIXME: we could write timezone_offset to From-line.. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
368 if (received_date == (time_t)-1) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
369 received_date = ioloop_time; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
370 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
371 if (ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
372 ctx = t->save_ctx = i_new(struct mbox_save_context, 1); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
373 ctx->ctx.transaction = &t->ictx.mailbox_ctx; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
374 ctx->mbox = mbox; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
375 ctx->trans = t->ictx.trans; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
376 ctx->append_offset = (uoff_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
377 ctx->headers = str_new(default_pool, 512); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
378 ctx->mail_offset = (uoff_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
379 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
380 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
381 ctx->failed = FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
382 ctx->seq = 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
383 |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
384 if (mbox_save_init_file(ctx, t, dest_mail != NULL) < 0) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
385 ctx->failed = TRUE; |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
386 return -1; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
387 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
388 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2986
diff
changeset
|
389 save_flags = (flags & ~MAIL_RECENT) | MAIL_RECENT; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
390 str_truncate(ctx->headers, 0); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
391 if (ctx->synced) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
392 str_printfa(ctx->headers, "X-UID: %u\n", ctx->next_uid); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
393 if (!mbox->ibox.keep_recent) |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
394 save_flags &= ~MAIL_RECENT; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
395 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
396 mail_index_append(ctx->trans, ctx->next_uid, &ctx->seq); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
397 mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2986
diff
changeset
|
398 save_flags); |
3471
138e242c53c9
Keywords weren't saved to index while saving.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
399 if (keywords != NULL) { |
138e242c53c9
Keywords weren't saved to index while saving.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
400 mail_index_update_keywords(ctx->trans, ctx->seq, |
138e242c53c9
Keywords weren't saved to index while saving.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
401 MODIFY_REPLACE, keywords); |
138e242c53c9
Keywords weren't saved to index while saving.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
402 } |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
403 |
2261
ba4f6d7b5a58
saving messages to empty mbox was buggy
Timo Sirainen <tss@iki.fi>
parents:
2224
diff
changeset
|
404 offset = ctx->output->offset == 0 ? 0 : |
ba4f6d7b5a58
saving messages to empty mbox was buggy
Timo Sirainen <tss@iki.fi>
parents:
2224
diff
changeset
|
405 ctx->output->offset - 1; |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2511
diff
changeset
|
406 mail_index_update_ext(ctx->trans, ctx->seq, |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
407 mbox->mbox_ext_idx, &offset, NULL); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
408 ctx->next_uid++; |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
409 |
3471
138e242c53c9
Keywords weren't saved to index while saving.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
410 /* parse and cache the mail headers as we read it */ |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
411 if (dest_mail == NULL) { |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
412 if (ctx->mail == NULL) |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
413 ctx->mail = index_mail_alloc(_t, 0, NULL); |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
414 dest_mail = ctx->mail; |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
415 } |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
416 if (mail_set_seq(dest_mail, ctx->seq) < 0) |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
417 i_unreached(); |
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
418 index_mail_parse_header_init((struct index_mail *)dest_mail, |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
419 NULL); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
420 } |
3250
3b820e59610e
Recent flag handling cleanups. Added some comments.
Timo Sirainen <tss@iki.fi>
parents:
3245
diff
changeset
|
421 mbox_save_append_flag_headers(ctx->headers, save_flags); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2986
diff
changeset
|
422 mbox_save_append_keyword_headers(ctx, keywords); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
423 str_append_c(ctx->headers, '\n'); |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
424 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
425 i_assert(mbox->mbox_lock_type == F_WRLCK); |
0 | 426 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
427 ctx->mail_offset = ctx->output->offset; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
428 ctx->eoh_input_offset = (uoff_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
429 ctx->eoh_offset = (uoff_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
430 ctx->last_char = '\n'; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
431 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
432 if (write_from_line(ctx, received_date, from_envelope) < 0) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
433 ctx->failed = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
434 else { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
435 ctx->input = |
2451
f6fef42f01b9
Changed istream-header-filter API a bit. Added HIDE_BODY option. Fixed
Timo Sirainen <tss@iki.fi>
parents:
2446
diff
changeset
|
436 i_stream_create_header_filter(input, |
f6fef42f01b9
Changed istream-header-filter API a bit. Added HIDE_BODY option. Fixed
Timo Sirainen <tss@iki.fi>
parents:
2446
diff
changeset
|
437 HEADER_FILTER_EXCLUDE | |
f6fef42f01b9
Changed istream-header-filter API a bit. Added HIDE_BODY option. Fixed
Timo Sirainen <tss@iki.fi>
parents:
2446
diff
changeset
|
438 HEADER_FILTER_NO_CR, |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
439 mbox_hide_headers, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
440 mbox_hide_headers_count, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
441 save_header_callback, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
442 ctx); |
3260
6a179bf1272e
Moved several getenv()s from lib-storage to main code. deliver binary was
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
443 ctx->body_output = |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
444 (STORAGE(mbox->storage)->flags & |
3260
6a179bf1272e
Moved several getenv()s from lib-storage to main code. deliver binary was
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
445 MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
446 o_stream_create_crlf(default_pool, ctx->output) : |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
447 o_stream_create_lf(default_pool, ctx->output); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
448 if (ctx->mbox->mbox_save_md5 && ctx->synced) |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
449 ctx->mbox_md5_ctx = mbox_md5_init(); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
450 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
451 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
452 *ctx_r = &ctx->ctx; |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
453 return ctx->failed ? -1 : 0; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
454 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
455 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
456 int mbox_save_continue(struct mail_save_context *_ctx) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
457 { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
458 struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
459 const unsigned char *data; |
2456 | 460 size_t size; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
461 ssize_t ret; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
462 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
463 if (ctx->failed) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
464 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
465 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
466 if (ctx->eoh_offset != (uoff_t)-1) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
467 /* writing body */ |
4412
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
468 while ((ret = i_stream_read(ctx->input)) != -1) { |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
469 if (ret == 0) |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
470 return 0; |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
471 |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
472 data = i_stream_get_data(ctx->input, &size); |
4527
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
473 if (o_stream_send(ctx->body_output, data, size) < 0) { |
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
474 write_error(ctx, |
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
475 ctx->body_output->stream_errno); |
4412
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
476 return -1; |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
477 } |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
478 ctx->last_char = data[size-1]; |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
479 i_stream_skip(ctx->input, size); |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
480 } |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
481 |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
482 if (ctx->last_char != '\n') { |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
483 /* if mail doesn't end with LF, we'll do that. |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
484 otherwise some mbox parsers don't like the result. |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
485 this makes it impossible to save a mail that doesn't |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
486 end with LF though. */ |
4527
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
487 if (o_stream_send(ctx->body_output, "\n", 1) < 0) { |
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
488 write_error(ctx, |
4c2155f3d72b
We wrote mail bodies through raw output stream, instead of the one that made
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
489 ctx->body_output->stream_errno); |
4412
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
490 return -1; |
521d07f9c247
If saved mail's body doesn't end with LF, add it ourself.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
491 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
492 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
493 return 0; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
494 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
495 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
496 while ((ret = i_stream_read(ctx->input)) != -1) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
497 if (ret == 0) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
498 return 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
499 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
500 data = i_stream_get_data(ctx->input, &size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
501 if (ctx->eoh_input_offset != (uoff_t)-1 && |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
502 ctx->input->v_offset + size >= ctx->eoh_input_offset) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
503 /* found end of headers. write the rest of them. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
504 size = ctx->eoh_input_offset - ctx->input->v_offset; |
2456 | 505 if (o_stream_send(ctx->output, data, size) < 0) { |
3348
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
506 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
507 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
508 } |
2456 | 509 if (size > 0) |
510 ctx->last_char = data[size-1]; | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
511 i_stream_skip(ctx->input, size + 1); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
512 break; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
513 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
514 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
515 if (o_stream_send(ctx->output, data, size) < 0) { |
3348
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
516 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
517 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
518 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
519 ctx->last_char = data[size-1]; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
520 i_stream_skip(ctx->input, size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
521 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
522 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
523 if (ctx->last_char != '\n') { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
524 if (o_stream_send(ctx->output, "\n", 1) < 0) { |
3348
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
525 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
526 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
527 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
528 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
529 |
2978
982e7432276f
If mbox isn't synced, don't try to set message's md5sum because it just
Timo Sirainen <tss@iki.fi>
parents:
2973
diff
changeset
|
530 if (ctx->mbox_md5_ctx) { |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
531 unsigned char hdr_md5_sum[16]; |
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
532 |
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
533 mbox_md5_finish(ctx->mbox_md5_ctx, hdr_md5_sum); |
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
534 mail_index_update_ext(ctx->trans, ctx->seq, |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
535 ctx->mbox->ibox.md5hdr_ext_idx, |
2973
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
536 hdr_md5_sum, NULL); |
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
537 } |
32cc9186d8eb
If we want MD5 sums in indexes, mail saving should also add them.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
538 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
539 /* append our own headers and ending empty line */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
540 ctx->extra_hdr_offset = ctx->output->offset; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
541 if (o_stream_send(ctx->output, str_data(ctx->headers), |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
542 str_len(ctx->headers)) < 0) { |
3348
34dea04a191e
Crashfix for some failure handling.
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
543 write_error(ctx, ctx->output->stream_errno); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
544 return -1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
545 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
546 ctx->eoh_offset = ctx->output->offset; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
547 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
548 /* write body */ |
2461 | 549 (void)i_stream_get_data(ctx->input, &size); |
550 return ctx->input->eof && size == 0 ? 0 : mbox_save_continue(_ctx); | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
551 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
552 |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
553 int mbox_save_finish(struct mail_save_context *_ctx) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
554 { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
555 struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
556 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
557 ctx->finished = TRUE; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
558 if (!ctx->failed) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
559 if (mbox_write_content_length(ctx) < 0 || |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
560 mbox_append_lf(ctx) < 0) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
561 ctx->failed = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
562 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
563 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
564 if (ctx->input != NULL) |
4070
71b8faa84ec6
Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents:
4044
diff
changeset
|
565 i_stream_destroy(&ctx->input); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
566 if (ctx->body_output != NULL) |
4070
71b8faa84ec6
Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents:
4044
diff
changeset
|
567 o_stream_destroy(&ctx->body_output); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
568 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
569 if (ctx->failed && ctx->mail_offset != (uoff_t)-1) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
570 /* saving this mail failed - truncate back to beginning of it */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
571 if (ftruncate(ctx->mbox->mbox_fd, (off_t)ctx->mail_offset) < 0) |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
572 mbox_set_syscall_error(ctx->mbox, "ftruncate()"); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
573 ctx->mail_offset = (uoff_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
574 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
575 |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
576 return ctx->failed ? -1 : 0; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
577 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
578 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
579 void mbox_save_cancel(struct mail_save_context *_ctx) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
580 { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
581 struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
582 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
583 ctx->failed = TRUE; |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4193
diff
changeset
|
584 (void)mbox_save_finish(_ctx); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
585 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
586 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
587 static void mbox_transaction_save_deinit(struct mbox_save_context *ctx) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
588 { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
589 i_assert(ctx->body_output == NULL); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
590 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
591 if (ctx->output != NULL) |
4070
71b8faa84ec6
Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents:
4044
diff
changeset
|
592 o_stream_destroy(&ctx->output); |
3464
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
593 if (ctx->mail != NULL) |
0661239a7034
Cache mail headers when saving mails to mbox. We should cache everything,
Timo Sirainen <tss@iki.fi>
parents:
3348
diff
changeset
|
594 index_mail_free(ctx->mail); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
595 str_free(&ctx->headers); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
596 i_free(ctx); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
597 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
598 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
599 int mbox_transaction_save_commit(struct mbox_save_context *ctx) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
600 { |
4562
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
601 struct stat st; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
602 int ret = 0; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
603 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
604 i_assert(ctx->finished); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
605 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
606 if (ctx->synced) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
607 mail_index_update_header(ctx->trans, |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
608 offsetof(struct mail_index_header, next_uid), |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
609 &ctx->next_uid, sizeof(ctx->next_uid), FALSE); |
4562
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
610 |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
611 if (fstat(ctx->mbox->mbox_fd, &st) < 0) { |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
612 mbox_set_syscall_error(ctx->mbox, "fstat()"); |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
613 ret = -1; |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
614 } else { |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
615 uint32_t sync_stamp = st.st_mtime; |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
616 uint64_t sync_size = st.st_size; |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
617 |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
618 mail_index_update_header(ctx->trans, |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
619 offsetof(struct mail_index_header, sync_stamp), |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
620 &sync_stamp, sizeof(sync_stamp), TRUE); |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
621 mail_index_update_header(ctx->trans, |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
622 offsetof(struct mail_index_header, sync_size), |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
623 &sync_size, sizeof(sync_size), TRUE); |
8b9933470cf8
After saving a mail with index being in synced state, update the sync_stamp
Timo Sirainen <tss@iki.fi>
parents:
4527
diff
changeset
|
624 } |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
625 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2129
diff
changeset
|
626 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
627 if (!ctx->synced && ctx->mbox->mbox_fd != -1 && |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
628 !ctx->mbox->mbox_writeonly) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
629 if (fdatasync(ctx->mbox->mbox_fd) < 0) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
630 mbox_set_syscall_error(ctx->mbox, "fdatasync()"); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
631 ret = -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
632 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
633 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
634 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
635 mbox_transaction_save_deinit(ctx); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
636 return ret; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
637 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
638 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
639 void mbox_transaction_save_rollback(struct mbox_save_context *ctx) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
640 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
641 struct mbox_mailbox *mbox = ctx->mbox; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
642 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
643 if (!ctx->finished) |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
644 mbox_save_cancel(&ctx->ctx); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3879
diff
changeset
|
645 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
646 if (ctx->append_offset != (uoff_t)-1 && mbox->mbox_fd != -1) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
647 i_assert(mbox->mbox_lock_type == F_WRLCK); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
648 |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
649 /* failed, truncate file back to original size. |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
650 output stream needs to be flushed before truncating |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
651 so unref() won't write anything. */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
652 o_stream_flush(ctx->output); |
562 | 653 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
654 if (ftruncate(mbox->mbox_fd, (off_t)ctx->append_offset) < 0) |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3262
diff
changeset
|
655 mbox_set_syscall_error(mbox, "ftruncate()"); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
656 } |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
657 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
658 mbox_transaction_save_deinit(ctx); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
659 } |