Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-mail/message-send.c @ 9261:51aee73e49a5 HEAD
maildir: When UIDVALIDITY changes, don't reset uid_next to 1 in uidlist.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 26 Jul 2009 23:36:12 -0400 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8531
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
12
a4423c83b2b0
moved lib-imap/imap-message-send.* into lib-mail/message-send.*
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
a4423c83b2b0
moved lib-imap/imap-message-send.* into lib-mail/message-send.*
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
437
diff
changeset
|
4 #include "istream.h" |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
437
diff
changeset
|
5 #include "ostream.h" |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
856
diff
changeset
|
6 #include "message-parser.h" |
12
a4423c83b2b0
moved lib-imap/imap-message-send.* into lib-mail/message-send.*
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "message-send.h" |
a4423c83b2b0
moved lib-imap/imap-message-send.* into lib-mail/message-send.*
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "message-size.h" |
a4423c83b2b0
moved lib-imap/imap-message-send.* into lib-mail/message-send.*
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
8526
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
10 int message_skip_virtual(struct istream *input, uoff_t virtual_skip, |
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
11 struct message_size *msg_size, |
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
12 bool cr_skipped, bool *last_cr) |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
13 { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
14 const unsigned char *msg; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
15 size_t i, size, startpos; |
8526
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
16 int ret; |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
17 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
18 if (virtual_skip == 0) { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
19 *last_cr = cr_skipped; |
8526
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
20 return 0; |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
21 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
22 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
23 *last_cr = FALSE; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
24 startpos = 0; |
8526
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
25 while ((ret = i_stream_read_data(input, &msg, &size, startpos)) > 0) { |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
26 for (i = startpos; i < size && virtual_skip > 0; i++) { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
27 virtual_skip--; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
28 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
29 if (msg[i] == '\r') { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
30 /* CR */ |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
31 if (virtual_skip == 0) |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
32 *last_cr = TRUE; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
33 } else if (msg[i] == '\n') { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
34 /* LF */ |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
35 if ((i == 0 && !cr_skipped) || |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
36 (i > 0 && msg[i-1] != '\r')) { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
37 /* missing CR */ |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
38 if (msg_size != NULL) |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
39 msg_size->virtual_size++; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
40 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
41 if (virtual_skip == 0) { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
42 /* CR/LF boundary */ |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
43 *last_cr = TRUE; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
44 break; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
45 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
46 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
47 virtual_skip--; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
48 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
49 |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
50 /* increase after making sure we didn't break |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
51 at virtual \r */ |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
52 if (msg_size != NULL) |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
53 msg_size->lines++; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
54 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
55 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
56 |
1891
118ed97bd25a
message_skip_virtual() calculated returned msg_size wrong. This could have
Timo Sirainen <tss@iki.fi>
parents:
1867
diff
changeset
|
57 i_stream_skip(input, i); |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
58 if (msg_size != NULL) { |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
59 msg_size->physical_size += i; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
60 msg_size->virtual_size += i; |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
61 } |
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
62 |
1891
118ed97bd25a
message_skip_virtual() calculated returned msg_size wrong. This could have
Timo Sirainen <tss@iki.fi>
parents:
1867
diff
changeset
|
63 if (i < size) |
8531
f63f26da3845
Crashfix to previous message parsing error handling changes.
Timo Sirainen <tss@iki.fi>
parents:
8526
diff
changeset
|
64 return 0; |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
65 |
1891
118ed97bd25a
message_skip_virtual() calculated returned msg_size wrong. This could have
Timo Sirainen <tss@iki.fi>
parents:
1867
diff
changeset
|
66 cr_skipped = msg[i-1] == '\r'; |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
67 } |
8526
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
68 i_assert(ret == -1); |
c63cc3580150
Message parsing/reading: If read returns failure, don't ignore the error.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
69 return input->stream_errno == 0 ? 0 : -1; |
1391
e0dbaabbc22b
Partial fetches were broken when they stopped between virtual CR and LF.
Timo Sirainen <tss@iki.fi>
parents:
991
diff
changeset
|
70 } |