Commit 012c66dd 012c66ddbbf4c852f2f26e1c075e7ddb808559c1 by Sergey Poznyakoff

Minor change

* libmailutils/mime/mime.c: Fix formatting
1 parent 447719f6
...@@ -70,9 +70,9 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg, ...@@ -70,9 +70,9 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg,
70 size_t offset, size_t len, size_t lines) 70 size_t offset, size_t len, size_t lines)
71 { 71 {
72 struct _mime_part *mime_part, **part_arr; 72 struct _mime_part *mime_part, **part_arr;
73 int ret; 73 int ret;
74 size_t size; 74 size_t size;
75 mu_header_t hdr; 75 mu_header_t hdr;
76 76
77 if ((mime_part = calloc (1, sizeof (*mime_part))) == NULL) 77 if ((mime_part = calloc (1, sizeof (*mime_part))) == NULL)
78 return ENOMEM; 78 return ENOMEM;
...@@ -147,8 +147,8 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg, ...@@ -147,8 +147,8 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg,
147 static void 147 static void
148 _mime_munge_content_header (char *field_body) 148 _mime_munge_content_header (char *field_body)
149 { 149 {
150 char *p, *e, *str = field_body; 150 char *p, *e, *str = field_body;
151 int quoted = 0; 151 int quoted = 0;
152 152
153 mu_str_stripws (field_body); 153 mu_str_stripws (field_body);
154 154
...@@ -184,8 +184,8 @@ _mime_munge_content_header (char *field_body) ...@@ -184,8 +184,8 @@ _mime_munge_content_header (char *field_body)
184 static char * 184 static char *
185 _mime_get_param (char *field_body, const char *param, int *len) 185 _mime_get_param (char *field_body, const char *param, int *len)
186 { 186 {
187 char *str, *p, *v, *e; 187 char *str, *p, *v, *e;
188 int quoted = 0, was_quoted; 188 int quoted = 0, was_quoted;
189 189
190 if (len == NULL || (str = field_body) == NULL) 190 if (len == NULL || (str = field_body) == NULL)
191 return NULL; 191 return NULL;
...@@ -242,11 +242,10 @@ _mime_append_header_line (mu_mime_t mime) ...@@ -242,11 +242,10 @@ _mime_append_header_line (mu_mime_t mime)
242 { 242 {
243 if (mime->header_length + mime->line_ndx > mime->header_buf_size) 243 if (mime->header_length + mime->line_ndx > mime->header_buf_size)
244 { 244 {
245 char *nhb; 245 char *nhb;
246 246
247 if ((nhb = 247 if ((nhb = realloc (mime->header_buf,
248 realloc (mime->header_buf, 248 mime->header_length + mime->line_ndx + 128)) == NULL)
249 mime->header_length + mime->line_ndx + 128)) == NULL)
250 return; 249 return;
251 mime->header_buf = nhb; 250 mime->header_buf = nhb;
252 mime->header_buf_size = mime->header_length + mime->line_ndx + 128; 251 mime->header_buf_size = mime->header_length + mime->line_ndx + 128;
...@@ -259,20 +258,20 @@ _mime_append_header_line (mu_mime_t mime) ...@@ -259,20 +258,20 @@ _mime_append_header_line (mu_mime_t mime)
259 static int 258 static int
260 _mime_parse_mpart_message (mu_mime_t mime) 259 _mime_parse_mpart_message (mu_mime_t mime)
261 { 260 {
262 char *cp, *cp2; 261 char *cp, *cp2;
263 size_t blength, mb_length, mb_offset, mb_lines; 262 size_t blength, mb_length, mb_offset, mb_lines;
264 int ret; 263 int ret;
265 size_t nbytes; 264 size_t nbytes;
266 265
267 if (!(mime->flags & MIME_PARSER_ACTIVE)) 266 if (!(mime->flags & MIME_PARSER_ACTIVE))
268 { 267 {
269 char *boundary; 268 char *boundary;
270 int len; 269 int len;
271 270
272 if ((ret = _mime_setup_buffers (mime)) != 0) 271 if ((ret = _mime_setup_buffers (mime)) != 0)
273 return ret; 272 return ret;
274 if ((boundary = 273 if ((boundary = _mime_get_param (mime->content_type, "boundary", &len))
275 _mime_get_param (mime->content_type, "boundary", &len)) == NULL) 274 == NULL)
276 return EINVAL; 275 return EINVAL;
277 if ((mime->boundary = calloc (1, len + 1)) == NULL) 276 if ((mime->boundary = calloc (1, len + 1)) == NULL)
278 return ENOMEM; 277 return ENOMEM;
...@@ -289,9 +288,8 @@ _mime_parse_mpart_message (mu_mime_t mime) ...@@ -289,9 +288,8 @@ _mime_parse_mpart_message (mu_mime_t mime)
289 blength = strlen (mime->boundary); 288 blength = strlen (mime->boundary);
290 289
291 mu_stream_seek (mime->stream, mime->cur_offset, MU_SEEK_SET, NULL); 290 mu_stream_seek (mime->stream, mime->cur_offset, MU_SEEK_SET, NULL);
292 while ((ret = 291 while ((ret = mu_stream_read (mime->stream, mime->cur_buf, mime->buf_size,
293 mu_stream_read (mime->stream, mime->cur_buf, mime->buf_size, 292 &nbytes)) == 0 && nbytes)
294 &nbytes)) == 0 && nbytes)
295 { 293 {
296 cp = mime->cur_buf; 294 cp = mime->cur_buf;
297 while (nbytes) 295 while (nbytes)
...@@ -308,9 +306,8 @@ _mime_parse_mpart_message (mu_mime_t mime) ...@@ -308,9 +306,8 @@ _mime_parse_mpart_message (mu_mime_t mime)
308 break; 306 break;
309 307
310 case MIME_STATE_SCAN_BOUNDARY: 308 case MIME_STATE_SCAN_BOUNDARY:
311 cp2 = 309 cp2 = mime->cur_line[0] == '\n'
312 mime->cur_line[0] == 310 ? mime->cur_line + 1 : mime->cur_line;
313 '\n' ? mime->cur_line + 1 : mime->cur_line;
314 if (mime->line_ndx >= blength) 311 if (mime->line_ndx >= blength)
315 { 312 {
316 if ((!strncmp (cp2, "--", 2) 313 if ((!strncmp (cp2, "--", 2)
...@@ -423,7 +420,7 @@ _mime_parse_mpart_message (mu_mime_t mime) ...@@ -423,7 +420,7 @@ _mime_parse_mpart_message (mu_mime_t mime)
423 static int 420 static int
424 _mimepart_body_size (mu_body_t body, size_t *psize) 421 _mimepart_body_size (mu_body_t body, size_t *psize)
425 { 422 {
426 mu_message_t msg = mu_body_get_owner (body); 423 mu_message_t msg = mu_body_get_owner (body);
427 struct _mime_part *mime_part = mu_message_get_owner (msg); 424 struct _mime_part *mime_part = mu_message_get_owner (msg);
428 425
429 if (mime_part == NULL) 426 if (mime_part == NULL)
...@@ -436,7 +433,7 @@ _mimepart_body_size (mu_body_t body, size_t *psize) ...@@ -436,7 +433,7 @@ _mimepart_body_size (mu_body_t body, size_t *psize)
436 static int 433 static int
437 _mimepart_body_lines (mu_body_t body, size_t *plines) 434 _mimepart_body_lines (mu_body_t body, size_t *plines)
438 { 435 {
439 mu_message_t msg = mu_body_get_owner (body); 436 mu_message_t msg = mu_body_get_owner (body);
440 struct _mime_part *mime_part = mu_message_get_owner (msg); 437 struct _mime_part *mime_part = mu_message_get_owner (msg);
441 438
442 if (mime_part == NULL) 439 if (mime_part == NULL)
...@@ -451,9 +448,9 @@ static int ...@@ -451,9 +448,9 @@ static int
451 _mime_set_content_type (mu_mime_t mime) 448 _mime_set_content_type (mu_mime_t mime)
452 { 449 {
453 const char *content_type; 450 const char *content_type;
454 mu_header_t hdr = NULL; 451 mu_header_t hdr = NULL;
455 size_t size; 452 size_t size;
456 int ret; 453 int ret;
457 454
458 /* Delayed the creation of the header 'til they create the final message via 455 /* Delayed the creation of the header 'til they create the final message via
459 mu_mime_get_message() */ 456 mu_mime_get_message() */
...@@ -657,12 +654,13 @@ _mime_body_stream_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult) ...@@ -657,12 +654,13 @@ _mime_body_stream_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
657 while (0) 654 while (0)
658 655
659 static int 656 static int
660 _mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen, size_t *nbytes) 657 _mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen,
658 size_t *nbytes)
661 { 659 {
662 struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream; 660 struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
663 mu_mime_t mime = mstr->mime; 661 mu_mime_t mime = mstr->mime;
664 int ret = 0; 662 int ret = 0;
665 size_t total = 0; 663 size_t total = 0;
666 664
667 if (mime->nmtp_parts == 0) 665 if (mime->nmtp_parts == 0)
668 { 666 {
...@@ -674,7 +672,7 @@ _mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen, size_t *nb ...@@ -674,7 +672,7 @@ _mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen, size_t *nb
674 { 672 {
675 do 673 do
676 { 674 {
677 size_t part_nbytes = 0; 675 size_t part_nbytes = 0;
678 676
679 if (buflen == 0) 677 if (buflen == 0)
680 break; 678 break;
...@@ -847,18 +845,18 @@ create_mime_body_stream (mu_stream_t *pstr, mu_mime_t mime) ...@@ -847,18 +845,18 @@ create_mime_body_stream (mu_stream_t *pstr, mu_mime_t mime)
847 static int 845 static int
848 _mime_body_size (mu_body_t body, size_t *psize) 846 _mime_body_size (mu_body_t body, size_t *psize)
849 { 847 {
850 mu_message_t msg = mu_body_get_owner (body); 848 mu_message_t msg = mu_body_get_owner (body);
851 mu_mime_t mime = mu_message_get_owner (msg); 849 mu_mime_t mime = mu_message_get_owner (msg);
852 return _mime_part_size (mime, psize); 850 return _mime_part_size (mime, psize);
853 } 851 }
854 852
855 static int 853 static int
856 _mime_body_lines (mu_body_t body, size_t *plines) 854 _mime_body_lines (mu_body_t body, size_t *plines)
857 { 855 {
858 mu_message_t msg = mu_body_get_owner (body); 856 mu_message_t msg = mu_body_get_owner (body);
859 mu_mime_t mime = mu_message_get_owner (msg); 857 mu_mime_t mime = mu_message_get_owner (msg);
860 int i, ret; 858 int i, ret;
861 size_t total = 0; 859 size_t total = 0;
862 860
863 if (mime->nmtp_parts == 0) 861 if (mime->nmtp_parts == 0)
864 { 862 {
...@@ -884,10 +882,10 @@ _mime_body_lines (mu_body_t body, size_t *plines) ...@@ -884,10 +882,10 @@ _mime_body_lines (mu_body_t body, size_t *plines)
884 int 882 int
885 mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags) 883 mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags)
886 { 884 {
887 mu_mime_t mime = NULL; 885 mu_mime_t mime = NULL;
888 int ret = 0; 886 int ret = 0;
889 size_t size; 887 size_t size;
890 mu_body_t body; 888 mu_body_t body;
891 889
892 if (pmime == NULL) 890 if (pmime == NULL)
893 return EINVAL; 891 return EINVAL;
...@@ -898,10 +896,9 @@ mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags) ...@@ -898,10 +896,9 @@ mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags)
898 { 896 {
899 if ((ret = mu_message_get_header (msg, &mime->hdrs)) == 0) 897 if ((ret = mu_message_get_header (msg, &mime->hdrs)) == 0)
900 { 898 {
901 if ((ret = 899 if ((ret = mu_header_get_value (mime->hdrs,
902 mu_header_get_value (mime->hdrs, 900 MU_HEADER_CONTENT_TYPE,
903 MU_HEADER_CONTENT_TYPE, 901 NULL, 0, &size)) == 0 && size)
904 NULL, 0, &size)) == 0 && size)
905 { 902 {
906 if ((mime->content_type = malloc (size + 1)) == NULL) 903 if ((mime->content_type = malloc (size + 1)) == NULL)
907 ret = ENOMEM; 904 ret = ENOMEM;
...@@ -1039,9 +1036,10 @@ mu_mime_get_part (mu_mime_t mime, size_t part, mu_message_t *msg) ...@@ -1039,9 +1036,10 @@ mu_mime_get_part (mu_mime_t mime, size_t part, mu_message_t *msg)
1039 if (ret == 0) 1036 if (ret == 0)
1040 { 1037 {
1041 mu_stream_set_flags (stream, 1038 mu_stream_set_flags (stream,
1042 MU_STREAM_READ | (flags & 1039 MU_STREAM_READ
1043 (MU_STREAM_SEEK 1040 | (flags &
1044 | MU_STREAM_NONBLOCK))); 1041 (MU_STREAM_SEEK
1042 | MU_STREAM_NONBLOCK)));
1045 mu_body_set_stream (body, stream, mime_part->msg); 1043 mu_body_set_stream (body, stream, mime_part->msg);
1046 mu_message_set_body (mime_part->msg, body, mime_part); 1044 mu_message_set_body (mime_part->msg, body, mime_part);
1047 mime_part->body_created = 1; 1045 mime_part->body_created = 1;
...@@ -1079,8 +1077,8 @@ mu_mime_get_num_parts (mu_mime_t mime, size_t *nmtp_parts) ...@@ -1079,8 +1077,8 @@ mu_mime_get_num_parts (mu_mime_t mime, size_t *nmtp_parts)
1079 int 1077 int
1080 mu_mime_add_part (mu_mime_t mime, mu_message_t msg) 1078 mu_mime_add_part (mu_mime_t mime, mu_message_t msg)
1081 { 1079 {
1082 int ret; 1080 int ret;
1083 1081
1084 if (mime == NULL || msg == NULL || (mime->flags & MIME_NEW_MESSAGE) == 0) 1082 if (mime == NULL || msg == NULL || (mime->flags & MIME_NEW_MESSAGE) == 0)
1085 return EINVAL; 1083 return EINVAL;
1086 if ((ret = _mime_append_part (mime, msg, 0, 0, 0)) == 0) 1084 if ((ret = _mime_append_part (mime, msg, 0, 0, 0)) == 0)
...@@ -1091,9 +1089,9 @@ mu_mime_add_part (mu_mime_t mime, mu_message_t msg) ...@@ -1091,9 +1089,9 @@ mu_mime_add_part (mu_mime_t mime, mu_message_t msg)
1091 int 1089 int
1092 mu_mime_get_message (mu_mime_t mime, mu_message_t *msg) 1090 mu_mime_get_message (mu_mime_t mime, mu_message_t *msg)
1093 { 1091 {
1094 mu_stream_t body_stream; 1092 mu_stream_t body_stream;
1095 mu_body_t body; 1093 mu_body_t body;
1096 int ret = 0; 1094 int ret = 0;
1097 1095
1098 if (mime == NULL || msg == NULL) 1096 if (mime == NULL || msg == NULL)
1099 return EINVAL; 1097 return EINVAL;
......