expire.c
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2005 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
#include "pop3d.h"
/* EXPIRE see RFC2449:
Implementation:
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)
{
mu_attribute_set_userflag (attr, POP3_ATTRIBUTE_RETR);
}
int
pop3d_is_retr (attribute_t attr)
{
return mu_attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR);
}
void
pop3d_unmark_retr (attribute_t attr)
{
if (mu_attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR))
mu_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 (mu_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))
mu_header_set_value (header, MU_HEADER_X_EXPIRE_TIMESTAMP, *value, 0);
if (header_is_expired (header))
mu_attribute_set_deleted (attr);
}
}