Commit 3eb194cd 3eb194cd68b0ee8ba15ee68de10e5c07328508b0 by Sergey Poznyakoff

(expire_mark_message): New function

1 parent fa578a40
......@@ -20,12 +20,19 @@
/* EXPIRE see RFC2449:
Implementation:
When a message is downloaded it is mark, pop3d_mark_retr(attr)
at the update state the expire date is set on a header field
asprintf (.. "X-Expire-Timestamp: %ld", (long)time(NULL));
The message is not actually remove, we rely on external
program to do it.
*/
When a message is downloaded by RETR, it is marked with
"X-Expire-Timestamp: N", where N is the current value of
UNIX timestamp.
If pop3d was started with --delete-expired, the messages whose
X-Expire-Timestamp is more than (time(NULL)-expire days) old
are deleted.
Otherwise, such messages remain in the mailbox and the system
administrator is supposed to run a cron job that purges the mailboxes
(easily done using GNU sieve timestamp extension).
*/
void
pop3d_mark_retr (attribute_t attr)
......@@ -45,3 +52,54 @@ pop3d_unmark_retr (attribute_t attr)
if (attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR))
attribute_unset_userflag (attr, POP3_ATTRIBUTE_RETR);
}
static int
header_is_expired (header_t hdr)
{
time_t timestamp;
char buf[64];
char *p;
if (!expire_on_exit)
return 0;
if (header_get_value (hdr, MU_HEADER_X_EXPIRE_TIMESTAMP,
buf, sizeof buf, NULL))
return 0;
timestamp = strtoul (buf, &p, 0);
while (*p && isspace (*p))
p++;
if (*p)
return 0;
return time (NULL) >= timestamp + expire * 86400;
}
/* If pop3d is started with --expire, add an expiration header to the message.
Additionally, if --deltete-expired option was given, mark
the message as deleted if its X-Expire-Timestamp is too old.
Arguments:
msg - Message to operate upon
value - Points to a character buffer where the value of
X-Expire-Timestamp is to be stored. *value must be set to
NULL upon the first invocation of this function */
void
expire_mark_message (message_t msg, char **value)
{
/* Mark the message with a timestamp. */
if (expire != EXPIRE_NEVER)
{
header_t header = NULL;
attribute_t attr = NULL;
if (!*value)
asprintf (value, "%lu", (unsigned long) time (NULL));
message_get_header (msg, &header);
message_get_attribute (msg, &attr);
if (pop3d_is_retr (attr))
header_set_value (header, MU_HEADER_X_EXPIRE_TIMESTAMP, *value, 0);
if (header_is_expired (header))
attribute_set_deleted (attr);
}
}
......