Commit d0bd03f4 d0bd03f4f67b4970f43ac22885a9897b84cb9ec0 by Alain Magloire

add expire to Makefile.am

Add EXPIRE in capa.c
new optio --expire in pop3d.c
in update state set the new header in quit.c
in retr.c mark the message Downloaded.
new file.
1 parent 35f50c31
...@@ -26,7 +26,7 @@ SUBDIRS = testsuite ...@@ -26,7 +26,7 @@ SUBDIRS = testsuite
26 26
27 pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \ 27 pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \
28 list.c lock.c noop.c quit.c retr.c rset.c stat.c stls.c signal.c top.c \ 28 list.c lock.c noop.c quit.c retr.c rset.c stat.c stls.c signal.c top.c \
29 uidl.c user.c logindelay.c 29 uidl.c user.c logindelay.c expire.c
30 30
31 pop3d_LDADD = \ 31 pop3d_LDADD = \
32 ../mailbox/mbox/libmu_mbox.la\ 32 ../mailbox/mbox/libmu_mbox.la\
......
...@@ -47,9 +47,12 @@ pop3d_capa (const char *arg) ...@@ -47,9 +47,12 @@ pop3d_capa (const char *arg)
47 pop3d_outf ("STLS\r\n"); 47 pop3d_outf ("STLS\r\n");
48 #endif /* WITH_TLS */ 48 #endif /* WITH_TLS */
49 49
50 /* FIXME: This can be Implemented by setting an header field on the 50 /* This can be Implemented by setting an header field on the message. */
51 message. */ 51 if (expire < 0)
52 /*pop3d_outf ("EXPIRE NEVER\r\n"); */ 52 pop3d_outf ("EXPIRE NEVER\r\n");
53 else
54 pop3d_outf ("EXPIRE %d\r\n", expire);
55
53 if (state == TRANSACTION) /* let's not advertise to just anyone */ 56 if (state == TRANSACTION) /* let's not advertise to just anyone */
54 pop3d_outf ("IMPLEMENTATION %s\r\n", PACKAGE_STRING); 57 pop3d_outf ("IMPLEMENTATION %s\r\n", PACKAGE_STRING);
55 pop3d_outf (".\r\n"); 58 pop3d_outf (".\r\n");
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 #include "pop3d.h"
19
20 /* EXPIRE see RFC2449:
21
22 Implementation:
23 When a message is downloaded it is mark, pop3d_mark_retr(attr)
24 at the update state the expire date is set on a header field
25 asprintf (.. "X-Expire-Timestamp: %ld", (long)time(NULL));
26 The message is not actually remove, we rely on external
27 program to do it.
28 */
29
30 void
31 pop3d_mark_retr (attribute_t attr)
32 {
33 attribute_set_userflag (attr, POP3_ATTRIBUTE_RETR);
34 }
35
36 int
37 pop3d_is_retr (attribute_t attr)
38 {
39 return attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR);
40 }
41
42 void
43 pop3d_unmark_retr (attribute_t attr)
44 {
45 if (attribute_is_userflag (attr, POP3_ATTRIBUTE_RETR))
46 attribute_unset_userflag (attr, POP3_ATTRIBUTE_RETR);
47 }
...@@ -47,6 +47,9 @@ time_t login_delay = 0; ...@@ -47,6 +47,9 @@ time_t login_delay = 0;
47 char *login_stat_file = LOGIN_STAT_FILE; 47 char *login_stat_file = LOGIN_STAT_FILE;
48 #endif 48 #endif
49 49
50 /* Minimum advertise retention times of messages. */
51 int expire = -1;
52
50 static int pop3d_mainloop __P ((int fd, FILE *, FILE *)); 53 static int pop3d_mainloop __P ((int fd, FILE *, FILE *));
51 static void pop3d_daemon_init __P ((void)); 54 static void pop3d_daemon_init __P ((void));
52 static void pop3d_daemon __P ((unsigned int, unsigned int)); 55 static void pop3d_daemon __P ((unsigned int, unsigned int));
...@@ -59,6 +62,7 @@ static char doc[] = N_("GNU pop3d -- the POP3 daemon"); ...@@ -59,6 +62,7 @@ static char doc[] = N_("GNU pop3d -- the POP3 daemon");
59 62
60 #define OPT_LOGIN_DELAY 257 63 #define OPT_LOGIN_DELAY 257
61 #define OPT_STAT_FILE 258 64 #define OPT_STAT_FILE 258
65 #define OPT_EXPIRE 259
62 66
63 static struct argp_option options[] = { 67 static struct argp_option options[] = {
64 {"undelete", 'u', NULL, 0, 68 {"undelete", 'u', NULL, 0,
...@@ -69,6 +73,8 @@ static struct argp_option options[] = { ...@@ -69,6 +73,8 @@ static struct argp_option options[] = {
69 {"stat-file", OPT_STAT_FILE, N_("FILENAME"), 0, 73 {"stat-file", OPT_STAT_FILE, N_("FILENAME"), 0,
70 N_("Name of login statistics file"), 0}, 74 N_("Name of login statistics file"), 0},
71 #endif 75 #endif
76 {"expire", OPT_EXPIRE, N_("DAYS"), 0,
77 N_("Minimum advertise retention days of messages, default -1 means NEVER"), 0},
72 {NULL, 0, NULL, 0, NULL, 0} 78 {NULL, 0, NULL, 0, NULL, 0}
73 }; 79 };
74 80
...@@ -122,8 +128,12 @@ pop3d_parse_opt (int key, char *arg, struct argp_state *astate) ...@@ -122,8 +128,12 @@ pop3d_parse_opt (int key, char *arg, struct argp_state *astate)
122 case OPT_STAT_FILE: 128 case OPT_STAT_FILE:
123 login_stat_file = arg; 129 login_stat_file = arg;
124 break; 130 break;
125
126 #endif 131 #endif
132
133 case OPT_STAT_FILE:
134 expire = strtoul (arg, &p, 10);
135 break;
136
127 default: 137 default:
128 return ARGP_ERR_UNKNOWN; 138 return ARGP_ERR_UNKNOWN;
129 } 139 }
......
...@@ -88,6 +88,9 @@ extern void update_login_delay __P((char *username)); ...@@ -88,6 +88,9 @@ extern void update_login_delay __P((char *username));
88 # define update_login_delay(u) 88 # define update_login_delay(u)
89 #endif 89 #endif
90 90
91 /* Minimum advertise retention time for messages. */
92 extern int expire;
93
91 /* Size of the MD5 digest for APOP */ 94 /* Size of the MD5 digest for APOP */
92 #define APOP_DIGEST 70 95 #define APOP_DIGEST 70
93 96
...@@ -165,6 +168,7 @@ extern void update_login_delay __P((char *username)); ...@@ -165,6 +168,7 @@ extern void update_login_delay __P((char *username));
165 #endif 168 #endif
166 169
167 #define POP3_ATTRIBUTE_DELE 0x0001 170 #define POP3_ATTRIBUTE_DELE 0x0001
171 #define POP3_ATTRIBUTE_RETR 0x0010
168 172
169 #define AUTHORIZATION 0 173 #define AUTHORIZATION 0
170 #define TRANSACTION 1 174 #define TRANSACTION 1
......
...@@ -62,16 +62,29 @@ pop3d_fix_mark () ...@@ -62,16 +62,29 @@ pop3d_fix_mark ()
62 { 62 {
63 size_t i; 63 size_t i;
64 size_t total = 0; 64 size_t total = 0;
65 char *value = NULL;
66 int len;
65 67
66 mailbox_messages_count (mbox, &total); 68 mailbox_messages_count (mbox, &total);
67 69 len = asprintf (&value, "%ul", (unsigned long) time (NULL));
68 for (i = 1; i <= total; i++) 70 for (i = 1; i <= total; i++)
69 { 71 {
70 message_t msg = NULL; 72 message_t msg = NULL;
71 attribute_t attr = NULL; 73 attribute_t attr = NULL;
72 mailbox_get_message (mbox, i, &msg); 74 mailbox_get_message (mbox, i, &msg);
73 message_get_attribute (msg, &attr); 75 message_get_attribute (msg, &attr);
76
74 if (pop3d_is_deleted (attr)) 77 if (pop3d_is_deleted (attr))
75 attribute_set_deleted (attr); 78 attribute_set_deleted (attr);
79
80 // Mark the message with a timestamp.
81 if (expire >= 0 && pop3d_is_retr (attr))
82 {
83 header_t header = NULL;
84 message_get_header (msg, &header);
85 header_set_value (header, "X-Expire-Timestamp", value, len);
86 }
76 } 87 }
88
89 free (value);
77 } 90 }
......
...@@ -77,6 +77,8 @@ pop3d_retr (const char *arg) ...@@ -77,6 +77,8 @@ pop3d_retr (const char *arg)
77 if (!attribute_is_read (attr)) 77 if (!attribute_is_read (attr))
78 attribute_set_read (attr); 78 attribute_set_read (attr);
79 79
80 pop3d_mark_retr (attr);
81
80 free (buf); 82 free (buf);
81 pop3d_outf (".\r\n"); 83 pop3d_outf (".\r\n");
82 84
......