~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib-mail/message-size.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "istream.h"
6
6
#include "message-size.h"
7
7
 
8
8
int message_get_header_size(struct istream *input, struct message_size *hdr,
9
 
                            bool *has_nuls)
 
9
                            bool *has_nuls_r)
10
10
{
11
11
        const unsigned char *msg;
12
12
        size_t i, size, startpos, missing_cr_count;
13
13
        int ret;
14
14
 
15
15
        memset(hdr, 0, sizeof(struct message_size));
16
 
        if (has_nuls != NULL)
17
 
                *has_nuls = FALSE;
 
16
        *has_nuls_r = FALSE;
18
17
 
19
18
        missing_cr_count = 0; startpos = 0;
20
19
        while (i_stream_read_data(input, &msg, &size, startpos) > 0) {
21
20
                for (i = startpos; i < size; i++) {
22
21
                        if (msg[i] != '\n') {
23
 
                                if (msg[i] == '\0' && has_nuls != NULL)
24
 
                                        *has_nuls = TRUE;
 
22
                                if (msg[i] == '\0')
 
23
                                        *has_nuls_r = TRUE;
25
24
                                continue;
26
25
                        }
27
26
 
65
64
}
66
65
 
67
66
int message_get_body_size(struct istream *input, struct message_size *body,
68
 
                          bool *has_nuls)
 
67
                          bool *has_nuls_r)
69
68
{
70
69
        const unsigned char *msg;
71
70
        size_t i, size, missing_cr_count;
72
71
        int ret;
73
72
 
74
73
        memset(body, 0, sizeof(struct message_size));
75
 
        if (has_nuls != NULL)
76
 
                *has_nuls = FALSE;
 
74
        *has_nuls_r = FALSE;
77
75
 
78
76
        missing_cr_count = 0;
79
77
        if ((ret = i_stream_read_data(input, &msg, &size, 0)) <= 0)
97
95
                                   at virtual \r */
98
96
                                body->lines++;
99
97
                        } else if (msg[i] == '\0') {
100
 
                                if (has_nuls != NULL)
101
 
                                        *has_nuls = TRUE;
 
98
                                *has_nuls_r = TRUE;
102
99
                        }
103
100
                }
104
101
 
124
121
        dest->physical_size += src->physical_size;
125
122
        dest->lines += src->lines;
126
123
}
 
124
 
 
125
int message_skip_virtual(struct istream *input, uoff_t virtual_skip,
 
126
                         bool *last_cr_r)
 
127
{
 
128
        const unsigned char *msg;
 
129
        size_t i, size;
 
130
        bool cr_skipped = FALSE;
 
131
        int ret;
 
132
 
 
133
        *last_cr_r = FALSE;
 
134
        if (virtual_skip == 0)
 
135
                return 0;
 
136
 
 
137
        while ((ret = i_stream_read_data(input, &msg, &size, 0)) > 0) {
 
138
                for (i = 0; i < size && virtual_skip > 0; i++) {
 
139
                        virtual_skip--;
 
140
 
 
141
                        if (msg[i] == '\r') {
 
142
                                /* CR */
 
143
                                if (virtual_skip == 0)
 
144
                                        *last_cr_r = TRUE;
 
145
                        } else if (msg[i] == '\n') {
 
146
                                /* LF */
 
147
                                if ((i == 0 && !cr_skipped) ||
 
148
                                    (i > 0 && msg[i-1] != '\r')) {
 
149
                                        if (virtual_skip == 0) {
 
150
                                                /* CR/LF boundary */
 
151
                                                *last_cr_r = TRUE;
 
152
                                                break;
 
153
                                        }
 
154
 
 
155
                                        virtual_skip--;
 
156
                                }
 
157
                        }
 
158
                }
 
159
                i_stream_skip(input, i);
 
160
 
 
161
                if (i < size)
 
162
                        return 0;
 
163
 
 
164
                cr_skipped = msg[i-1] == '\r';
 
165
        }
 
166
        i_assert(ret == -1);
 
167
        return input->stream_errno == 0 ? 0 : -1;
 
168
}