62 |
|
|
63 |
#define MAX_OPEN_STREAMS 16 |
#define MAX_OPEN_STREAMS 16 |
64 |
|
|
65 |
|
#define MH_ENV_SENDER_HEADER "X-Envelope-Sender" |
66 |
|
#define MH_ENV_DATE_HEADER "X-Envelope-Date" |
67 |
|
|
68 |
/* Note: In this particular implementation the message sequence number |
/* Note: In this particular implementation the message sequence number |
69 |
serves also as its UID. This allows to avoid many problems related |
serves also as its UID. This allows to avoid many problems related |
70 |
to keeping the uids in the headers of the messages. */ |
to keeping the uids in the headers of the messages. */ |
478 |
int status; |
int status; |
479 |
attribute_t attr; |
attribute_t attr; |
480 |
body_t body; |
body_t body; |
481 |
|
char buffer[512]; |
482 |
|
envelope_t env = NULL; |
483 |
|
|
484 |
if (expunge) |
if (expunge) |
485 |
fp = _mh_tempfile (mhm->mhd, &name); |
fp = _mh_tempfile (mhm->mhd, &name); |
486 |
else |
else |
524 |
|
|
525 |
if (!(strncasecmp (buf, "status:", 7) == 0 |
if (!(strncasecmp (buf, "status:", 7) == 0 |
526 |
|| strncasecmp (buf, "x-imapbase:", 11) == 0 |
|| strncasecmp (buf, "x-imapbase:", 11) == 0 |
527 |
|| strncasecmp (buf, "x-uid:", 6) == 0)) |
|| strncasecmp (buf, "x-uid:", 6) == 0 |
528 |
|
|| strncasecmp (buf, MH_ENV_DATE_HEADER ":", sizeof (MH_ENV_DATE_HEADER)) == 0 |
529 |
|
|| strncasecmp (buf, MH_ENV_SENDER_HEADER ":", sizeof (MH_ENV_SENDER_HEADER)) == 0)) |
530 |
fprintf (fp, "%s", buf); |
fprintf (fp, "%s", buf); |
531 |
off += n; |
off += n; |
532 |
} |
} |
538 |
if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/ |
if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/ |
539 |
fprintf (fp, "X-IMAPbase: %lu %u\n", mhd->uidvalidity, _mh_next_seq(mhd)); |
fprintf (fp, "X-IMAPbase: %lu %u\n", mhd->uidvalidity, _mh_next_seq(mhd)); |
540 |
|
|
541 |
|
message_get_envelope (msg, &env); |
542 |
|
if (envelope_date (env, buffer, sizeof buffer, &n) == 0 && n > 0) |
543 |
|
fprintf (fp, "%s: %s\n", MH_ENV_DATE_HEADER, buffer); |
544 |
|
if (envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0) |
545 |
|
fprintf (fp, "%s: %s\n", MH_ENV_SENDER_HEADER, buffer); |
546 |
|
|
547 |
/* Add status */ |
/* Add status */ |
548 |
message_get_attribute (msg, &attr); |
message_get_attribute (msg, &attr); |
549 |
attribute_to_string (attr, buf, bsize, &n); |
attribute_to_string (attr, buf, bsize, &n); |
1354 |
{ |
{ |
1355 |
message_t msg = envelope_get_owner (envelope); |
message_t msg = envelope_get_owner (envelope); |
1356 |
struct _mh_message *mhm = message_get_owner (msg); |
struct _mh_message *mhm = message_get_owner (msg); |
1357 |
size_t n = 0; |
header_t hdr = NULL; |
1358 |
|
char *from; |
1359 |
int status; |
int status; |
1360 |
char buffer[512]; |
|
|
char *s; |
|
|
|
|
1361 |
if (mhm == NULL) |
if (mhm == NULL) |
1362 |
return EINVAL; |
return EINVAL; |
1363 |
|
|
1364 |
mh_pool_open (mhm); |
if ((status = message_get_header (msg, &hdr)) != 0) |
1365 |
|
return status; |
1366 |
status = stream_readline (mhm->stream, buffer, sizeof(buffer), 0, &n); |
if (header_aget_value (hdr, MH_ENV_DATE_HEADER, &from)) |
1367 |
if (status != 0) |
return ENOSYS; |
|
{ |
|
|
if (psize) |
|
|
*psize = 0; |
|
|
return status; |
|
|
} |
|
1368 |
|
|
1369 |
/* Format: "From [sender] [date]" */ |
/* Format: "sender date" */ |
1370 |
/* strlen ("From ") == 5 */ |
if (buf && len > 0) |
|
if (n > 5 && (s = strchr (buffer + 5, ' ')) != NULL) |
|
1371 |
{ |
{ |
1372 |
if (buf && len > 0) |
len--; /* Leave space for the null. */ |
1373 |
{ |
strncpy (buf, from, len); |
1374 |
len--; /* Leave space for the null. */ |
buf[len] = '\0'; |
1375 |
strncpy (buf, s + 1, len)[len] = '\0'; |
len = strlen (buf); |
|
len = strlen (buf); |
|
|
} |
|
|
else |
|
|
len = strlen (s + 1); |
|
1376 |
} |
} |
1377 |
else |
else |
1378 |
len = 0; |
len = 0; |
1387 |
{ |
{ |
1388 |
message_t msg = envelope_get_owner (envelope); |
message_t msg = envelope_get_owner (envelope); |
1389 |
struct _mh_message *mhm = message_get_owner (msg); |
struct _mh_message *mhm = message_get_owner (msg); |
1390 |
size_t n = 0; |
header_t hdr = NULL; |
1391 |
|
char *from; |
1392 |
int status; |
int status; |
|
char buffer[512]; |
|
|
char *s; |
|
1393 |
|
|
1394 |
if (mhm == NULL) |
if (mhm == NULL) |
1395 |
return EINVAL; |
return EINVAL; |
1396 |
|
|
1397 |
mh_pool_open (mhm); |
if ((status = message_get_header (msg, &hdr)) != 0) |
1398 |
|
return status; |
1399 |
|
if (header_aget_value (hdr, MH_ENV_SENDER_HEADER, &from)) |
1400 |
|
return ENOSYS; |
1401 |
|
|
1402 |
status = stream_readline (mhm->stream, buffer, sizeof(buffer), 0, &n); |
if (buf && len > 0) |
|
if (status != 0) |
|
1403 |
{ |
{ |
1404 |
if (psize) |
int slen = strlen (from) + 1; |
|
*psize = 0; |
|
|
return status; |
|
|
} |
|
1405 |
|
|
1406 |
/* Format: "From [sender] [date]" */ |
if (len <= slen) |
1407 |
/* strlen ("From ") == 5 */ |
slen = len - 1; |
1408 |
if (n > 5 && (s = strchr (buffer + 5, ' ')) != NULL) |
memcpy (buf, from, slen - 1); |
1409 |
{ |
buf[slen] = 0; |
|
/* Put a NULL to isolate the sender string, make a C string. */ |
|
|
*s = '\0'; |
|
|
if (buf && len > 0) |
|
|
{ |
|
|
len--; /* leave space for the null */ |
|
|
strncpy (buf, buffer + 5, len)[len] = '\0'; |
|
|
len = strlen (buf); |
|
|
} |
|
|
else |
|
|
len = strlen (buffer + 5); |
|
1410 |
} |
} |
1411 |
else |
else |
1412 |
len = 0; |
len = 0; |