Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/vacation - Fix bug in the determination of apparentl...
details: https://anonhg.NetBSD.org/src/rev/2c5d20b28818
branches: trunk
changeset: 565293:2c5d20b28818
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 03 20:55:13 2004 +0000
description:
- Fix bug in the determination of apparently-to and delivered-to.
- Add -f flag to look in Sender:, From:, and Return-Path: for the sender.
diffstat:
usr.bin/vacation/vacation.1 | 9 +++-
usr.bin/vacation/vacation.c | 106 +++++++++++++++++++++++++++++++++----------
2 files changed, 88 insertions(+), 27 deletions(-)
diffs (214 lines):
diff -r 16979835d205 -r 2c5d20b28818 usr.bin/vacation/vacation.1
--- a/usr.bin/vacation/vacation.1 Sat Apr 03 19:51:14 2004 +0000
+++ b/usr.bin/vacation/vacation.1 Sat Apr 03 20:55:13 2004 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: vacation.1,v 1.21 2003/08/07 11:16:59 agc Exp $
+.\" $NetBSD: vacation.1,v 1.22 2004/04/03 20:55:13 christos Exp $
.\"
.\" Copyright (c) 1985, 1987, 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -40,10 +40,12 @@
.Sh SYNOPSIS
.Nm
.Fl i
+.Op Fl f Ar F|R|S
.Op Fl r Ar interval
.Op Fl t Ar A|D
.Nm
.Op Fl a Ar alias
+.Op Fl f Ar F|R|S
.Op Fl t Ar A|D
.Ar login
.Sh DESCRIPTION
@@ -72,6 +74,11 @@
.Ar alias
in the same manner as those received for the user's
login name.
+.It Fl f Ar F|R|S
+Make
+.Nm
+look in addition to From: (F), Return-Path: (R), or Sender: (S) headers
+to determine the From: field.
.It Fl i
Initialize the vacation database files.
It should be used before you modify your
diff -r 16979835d205 -r 2c5d20b28818 usr.bin/vacation/vacation.c
--- a/usr.bin/vacation/vacation.c Sat Apr 03 19:51:14 2004 +0000
+++ b/usr.bin/vacation/vacation.c Sat Apr 03 20:55:13 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vacation.c,v 1.24 2003/08/07 11:16:59 agc Exp $ */
+/* $NetBSD: vacation.c,v 1.25 2004/04/03 20:55:13 christos Exp $ */
/*
* Copyright (c) 1983, 1987, 1993
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)vacation.c 8.2 (Berkeley) 1/26/94";
#endif
-__RCSID("$NetBSD: vacation.c,v 1.24 2003/08/07 11:16:59 agc Exp $");
+__RCSID("$NetBSD: vacation.c,v 1.25 2004/04/03 20:55:13 christos Exp $");
#endif /* not lint */
/*
@@ -89,14 +89,19 @@
DB *db;
char from[MAXLINE];
static int tflag = 0;
-#define APPARENTLY_TO 1
-#define DELIVERED_TO 2
+#define APPARENTLY_TO 1
+#define DELIVERED_TO 2
+static int fflag = 0;
+#define FROM_FROM 1
+#define RETURN_PATH_FROM 2
+#define SENDER_FROM 4
int main(int, char **);
int junkmail(void);
int nsearch(const char *, const char *);
void readheaders(void);
int recent(void);
+void getfrom(char *);
void sendmessage(const char *);
void setinterval(time_t);
void setreply(void);
@@ -113,8 +118,8 @@
opterr = iflag = 0;
interval = -1;
- openlog("vacation", 0, LOG_USER);
- while ((ch = getopt(argc, argv, "a:Iir:t:")) != -1)
+ openlog(getprogname(), 0, LOG_USER);
+ while ((ch = getopt(argc, argv, "a:f:Iir:t:")) != -1)
switch((char)ch) {
case 'a': /* alias */
if (!(cur = (alias_t *)malloc((size_t)sizeof(alias_t))))
@@ -123,6 +128,22 @@
cur->next = names;
names = cur;
break;
+ case 'f':
+ for (p = optarg; *p; p++)
+ switch (*p) {
+ case 'F':
+ fflag |= FROM_FROM;
+ break;
+ case 'R':
+ fflag |= RETURN_PATH_FROM;
+ break;
+ case 'S':
+ fflag |= SENDER_FROM;
+ break;
+ default:
+ errx(1, "Unknown -f option `%c'", *p);
+ }
+ break;
case 'I': /* backward compatible */
case 'i': /* init the database */
iflag = 1;
@@ -223,18 +244,13 @@
cont = tome = 0;
while (fgets(buf, sizeof(buf), stdin) && *buf != '\n')
switch(*buf) {
- case 'F': /* "From " */
- /* XXX should instead consider Return-Path: and Sender: */
+ case 'F': /* "From " or "From:" */
cont = 0;
- if (!strncmp(buf, "From ", 5)) {
- for (p = buf + 5; *p && *p != ' '; ++p);
- *p = '\0';
- (void)strlcpy(from, buf + 5, sizeof(from));
- if ((p = strchr(from, '\n')))
- *p = '\0';
- if (junkmail())
- exit(0);
- }
+ if (!strncmp(buf, "From ", 5))
+ getfrom(buf + 5);
+ if ((fflag & FROM_FROM) == 0 ||
+ strncmp(buf, "From:", 5))
+ getfrom(buf + 5);
break;
case 'P': /* "Precedence:" */
cont = 0;
@@ -244,7 +260,8 @@
break;
if (!(p = strchr(buf, ':')))
break;
- while (*++p && isspace((unsigned char)*p));
+ while (*++p && isspace((unsigned char)*p))
+ continue;
if (!*p)
break;
if (!strncasecmp(p, "junk", 4) ||
@@ -262,18 +279,30 @@
break;
cont = 1;
goto findme;
- case 'A':
+ case 'A': /* "Apparently-To:" */
if ((tflag & APPARENTLY_TO) == 0 ||
- strncmp(buf, "Apparently-To:", 3))
+ strncmp(buf, "Apparently-To:", 14))
+ break;
+ cont = 1;
+ goto findme;
+ case 'D': /* "Delivered-To:" */
+ if ((tflag & DELIVERED_TO) == 0 ||
+ strncmp(buf, "Delivered-To:", 13))
break;
cont = 1;
goto findme;
- case 'D':
- if ((tflag & DELIVERED_TO) == 0 ||
- strncmp(buf, "Delivered-To:", 3))
- break;
- cont = 1;
- goto findme;
+ case 'R': /* "Return-Path:" */
+ cont = 0;
+ if ((fflag & RETURN_PATH_FROM) == 0 ||
+ strncmp(buf, "Return-Path:", 12))
+ getfrom(buf + 12);
+ break;
+ case 'S': /* "Sender:" */
+ cont = 0;
+ if ((fflag & SENDER_FROM) == 0 ||
+ strncmp(buf, "Sender:", 7))
+ getfrom(buf + 7);
+ break;
default:
if (!isspace((unsigned char)*buf) || !cont || tome) {
cont = 0;
@@ -306,6 +335,31 @@
}
/*
+ * getfrom --
+ * return the first string in the buffer, stripping leading and trailing
+ * blanks and <>.
+ */
+void
+getfrom(char *buf)
+{
+ char *s, *p;
+
+ for (s = buf; *s && isspace((unsigned char)*s); s++)
+ continue;
+ if (*s == '<')
+ *s++;
+ for (p = s; *p && !isspace((unsigned char)*p); p++)
+ continue;
+ if (*--p == '>')
+ *p = '\0';
+ else
+ *p = '\0';
+ (void)strlcpy(from, s, sizeof(from));
+ if (junkmail())
+ exit(0);
+}
+
+/*
* junkmail --
* read the header and return if automagic/junk/bulk/list mail
*/
Home |
Main Index |
Thread Index |
Old Index