Commit 3eb194cd 3eb194cd68b0ee8ba15ee68de10e5c07328508b0 by Sergey Poznyakoff

(expire_mark_message): New function

1 parent fa578a40
...@@ -20,12 +20,19 @@ ...@@ -20,12 +20,19 @@
20 /* EXPIRE see RFC2449: 20 /* EXPIRE see RFC2449:
21 21
22 Implementation: 22 Implementation:
23 When a message is downloaded it is mark, pop3d_mark_retr(attr) 23 When a message is downloaded by RETR, it is marked with
24 at the update state the expire date is set on a header field 24 "X-Expire-Timestamp: N", where N is the current value of
25 asprintf (.. "X-Expire-Timestamp: %ld", (long)time(NULL)); 25 UNIX timestamp.
26 The message is not actually remove, we rely on external 26
27 program to do it. 27 If pop3d was started with --delete-expired, the messages whose
28 */ 28 X-Expire-Timestamp is more than (time(NULL)-expire days) old
29 are deleted.
30
31 Otherwise, such messages remain in the mailbox and the system
32 administrator is supposed to run a cron job that purges the mailboxes
33 (easily done using GNU sieve timestamp extension).
34
35 */
29 36
30 void 37 void
31 pop3d_mark_retr (attribute_t attr) 38 pop3d_mark_retr (attribute_t attr)
...@@ -45,3 +52,54 @@ pop3d_unmark_retr (attribute_t attr) ...@@ -45,3 +52,54 @@ pop3d_unmark_retr (attribute_t attr)
45 if (attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR)) 52 if (attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR))
46 attribute_unset_userflag (attr, POP3_ATTRIBUTE_RETR); 53 attribute_unset_userflag (attr, POP3_ATTRIBUTE_RETR);
47 } 54 }
55
56 static int
57 header_is_expired (header_t hdr)
58 {
59 time_t timestamp;
60 char buf[64];
61 char *p;
62
63 if (!expire_on_exit)
64 return 0;
65 if (header_get_value (hdr, MU_HEADER_X_EXPIRE_TIMESTAMP,
66 buf, sizeof buf, NULL))
67 return 0;
68 timestamp = strtoul (buf, &p, 0);
69 while (*p && isspace (*p))
70 p++;
71 if (*p)
72 return 0;
73 return time (NULL) >= timestamp + expire * 86400;
74 }
75
76 /* If pop3d is started with --expire, add an expiration header to the message.
77 Additionally, if --deltete-expired option was given, mark
78 the message as deleted if its X-Expire-Timestamp is too old.
79 Arguments:
80 msg - Message to operate upon
81 value - Points to a character buffer where the value of
82 X-Expire-Timestamp is to be stored. *value must be set to
83 NULL upon the first invocation of this function */
84 void
85 expire_mark_message (message_t msg, char **value)
86 {
87 /* Mark the message with a timestamp. */
88 if (expire != EXPIRE_NEVER)
89 {
90 header_t header = NULL;
91 attribute_t attr = NULL;
92
93 if (!*value)
94 asprintf (value, "%lu", (unsigned long) time (NULL));
95
96 message_get_header (msg, &header);
97 message_get_attribute (msg, &attr);
98
99 if (pop3d_is_retr (attr))
100 header_set_value (header, MU_HEADER_X_EXPIRE_TIMESTAMP, *value, 0);
101
102 if (header_is_expired (header))
103 attribute_set_deleted (attr);
104 }
105 }
......