File: realfrom.c

package info (click to toggle)
xbuffy 3.3.bl.3-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 408 kB
  • ctags: 276
  • sloc: ansic: 2,863; sh: 216; makefile: 115
file content (124 lines) | stat: -rw-r--r-- 2,683 bytes parent folder | download | duplicates (5)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
 *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
 *
 * 			Copyright (c) 1993 USENET Community Trust
 *******************************************************************************/

/* I've deleted a lot of stuff for xbuffy */

#include <stdio.h>
#include <ctype.h>
#include "xbuffy.h"

#ifdef WFP_DEBUG
#include "/home/wfp5p/bin/debug_include/malloc.h"
#endif


#ifdef BSD
#undef tolower
#undef toupper
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define whitespace(c)    (c == ' ' || c == '\t')


static char *month_name[13] = {
	"jan", "feb", "mar", "apr", "may", "jun",
	"jul", "aug", "sep", "oct", "nov", "dec", NULL
};

static char *day_name[8] = {
	"sun", "mon", "tue", "wed", "thu", "fri", "sat", 0
};


int real_from(buffer)
	char *buffer;
{

	/*
	   Breakup and validate the "From_" line in the "buffer".  If "entry" is
	   not NULL then the structure is filled in with sender and time
	   information.  Returns TRUE if the "From_" line is valid, otherwise
	   FALSE.
	
	A valid from line will be in the following format:
	
	From <user> <weekday> <month> <day> <hr:min:sec> [TZ1 [TZ2]] <year> [remote
	   from sitelist]
	
	We insist that all of the <angle bracket> fields are present. If two
	   timezone fields are present, the first is used for date information.  We
	   do not look at anything beyond the <year> field. We just insist that
	   everything up to the <year> field is present and valid.
	*/

	char field[255];			/* buffer for current field of line	 */
	int len;					/* length of current field		 */
	int day;
	int i;
	int found;


	/* From */

	if (strncmp(buffer, "From ", 5) != 0)
		goto failed;

	buffer += 5;


	/* <user> */
	if ((len = get_word(buffer, 0, field, sizeof(field))) < 0)
		goto failed;
	buffer += len;

	/* <weekday> */
	if ((len = get_word(buffer, 0, field, sizeof(field))) < 0)
		goto failed;
	else
	{
		found = 0;
		for (i = 0; day_name[i] != NULL; i++)
			found = found || (strincmp(day_name[i], field, 3) == 0);
		if (!found)
			goto failed;
	}

	buffer += len;

	/* <month> */
	if ((len = get_word(buffer, 0, field, sizeof(field))) < 0)
		goto failed;
	else
	{
		found = 0;
		for (i = 0; month_name[i] != NULL; i++)
			found = found || (strincmp(month_name[i], field, 3) == 0);
		if (!found)
			goto failed;
	}
	buffer += len;

	/* <day> */
	if ((len = get_word(buffer, 0, field, sizeof(field))) < 0 ||
		(day = atoi(field)) < 0 || day < 1 || day > 31)
		goto failed;
	buffer += len;


	/* The line is parsed and valid.  There might be more but we don't care. */
	return TRUE;

failed:
	return FALSE;
}