summaryrefslogtreecommitdiff
path: root/mail/mini_sendmail/patches/patch-aa
blob: dfd3bd6461c18d2b7cea3b17b391627ffb51912f (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
$NetBSD: patch-aa,v 1.9 2006/12/01 10:40:48 martin Exp $

--- mini_sendmail.c.orig	2005-06-29 19:37:15.000000000 +0200
+++ mini_sendmail.c	2006-12-01 11:35:27.000000000 +0100
@@ -66,8 +66,13 @@ static char* argv0;
 static char* fake_from;
 static int parse_message, verbose;
 #ifdef DO_MINUS_SP
-static char* server;
 static short port;
+struct server_entry {
+	const char *server;
+	short port;
+	struct server_entry *next;
+};
+struct server_entry *servers;
 #endif /* DO_MINUS_SP */
 static int timeout;
 static int sockfd1, sockfd2;
@@ -84,7 +89,7 @@ static char* make_received( char* from, 
 #endif /* DO_RECEIVED */
 static void parse_for_recipients( char* message );
 static void add_recipient( char* recipient, int len );
-static int open_client_socket( void );
+static int open_client_socket( const char *server, short port );
 static int read_response( void );
 static void send_command( char* command );
 static void send_data( char* data );
@@ -106,13 +111,15 @@ main( int argc, char** argv )
     char from[1000];
     int status;
     char buf[2000];
+#ifdef DO_MINUS_SP
+    struct server_entry *cur_server;
+#endif
 
     /* Parse args. */
     argv0 = argv[0];
     fake_from = (char*) 0;
     parse_message = 0;
 #ifdef DO_MINUS_SP
-    server = "127.0.0.1";
     port = SMTP_PORT;
 #endif /* DO_MINUS_SP */
     verbose = 0;
@@ -125,15 +132,21 @@ main( int argc, char** argv )
 	else if ( strcmp( argv[argn], "-t" ) == 0 )
 	    parse_message = 1;
 #ifdef DO_MINUS_SP
-	else if ( strncmp( argv[argn], "-s", 2 ) == 0 && argv[argn][2] != '\0' )
-	    server = &(argv[argn][2]);
-	else if ( strncmp( argv[argn], "-p", 2 ) == 0 && argv[argn][2] != '\0' )
+	else if ( strncmp( argv[argn], "-s", 2 ) == 0 && argv[argn][2] != '\0' ) {
+	    cur_server = malloc(sizeof(struct server_entry));
+	    cur_server->server = &(argv[argn][2]);
+	    cur_server->port = port;
+	    cur_server->next = servers;
+	    servers = cur_server;
+	} else if ( strncmp( argv[argn], "-p", 2 ) == 0 && argv[argn][2] != '\0' )
 	    port = atoi( &(argv[argn][2]) );
 #endif /* DO_MINUS_SP */
 	else if ( strncmp( argv[argn], "-T", 2 ) == 0 && argv[argn][2] != '\0' )
 	    timeout = atoi( &(argv[argn][2]) );
 	else if ( strcmp( argv[argn], "-v" ) == 0 )
 	    verbose = 1;
+	else if ( strcmp( argv[argn], "-oeq" ) == 0 )
+	    verbose = 0;
 	else if ( strcmp( argv[argn], "-i" ) == 0 )
 	    ;	/* ignore */
 	else if ( strcmp( argv[argn], "-oi" ) == 0 )
@@ -186,8 +199,21 @@ main( int argc, char** argv )
 
     (void) signal( SIGALRM, sigcatch );
 
+    if (!servers) {
+    	static const char default_server[] = "127.0.0.1";
+    	servers = malloc(sizeof(struct server_entry));
+    	servers->server = default_server;
+    	servers->port = port;
+    	servers->next = NULL;
+    }
+
     (void) alarm( timeout );
-    sockfd1 = open_client_socket();
+    for (cur_server = servers; cur_server; cur_server = cur_server->next) {
+	    sockfd1 = open_client_socket(cur_server->server, cur_server->port);
+	    if (sockfd1 >= 0) break;
+    }
+    if (sockfd1 == -1)
+    	show_error("could not open SMTP socket");
 
     sockfd2 = dup( sockfd1 );
     sockrfp = fdopen( sockfd1, "r" );
@@ -507,14 +533,24 @@ parse_for_recipients( char* message )
 	    switch ( *cp )
 		{
 		case '\n':
-		add_recipient( recip, ( cp - recip ) );
-		state = ST_BOL;
-		if ( bcc != (char*) 0 )
+		/* peek ahead for continuation line */
+		switch (cp[1])
 		    {
-		    /* Elide the Bcc: line, and reset cp. */
-		    (void) strcpy( bcc, cp + 1 );
-		    cp = bcc - 1;
-		    bcc = (char*) 0;
+		    case ' ':
+		    case '\t':
+		    break;
+
+		    default:
+		    add_recipient( recip, ( cp - recip ) );
+		    state = ST_BOL;
+		    if ( bcc != (char*) 0 )
+			{
+			/* Elide the Bcc: line, and reset cp. */
+			(void) strcpy( bcc, cp + 1 );
+			cp = bcc - 1;
+			bcc = (char*) 0;
+			}
+		    break;
 		    }
 		break;
 		case ',':
@@ -532,25 +568,43 @@ static void
 add_recipient( char* recipient, int len )
     {
     char buf[1000];
+    char *first;
     int status;
+    int i;
+
 
     /* Skip leading whitespace. */
-    while ( len > 0 && ( *recipient == ' ' || *recipient == '\t' ) )
+    while ( len > 0 && ( *recipient == ' ' || *recipient == '\t' ||
+			 *recipient == '\n') )
 	{
 	++recipient;
 	--len;
 	}
 
-    /* Strip off any angle brackets. */
-    while ( len > 0 && *recipient == '<' )
+    first = recipient;
+    /* search for angle bracket */
+
+    while (first < recipient+len && *first != '<')
 	{
-	++recipient;
-	--len;
+	++first;
 	}
-    while ( len > 0 && recipient[len-1] == '>' )
-	--len;
+
+    if (*first == '<')
+	{
+	len -= first + 1 - recipient;
+	recipient = first + 1;
+
+	while (len > 2 && recipient[--len] != '>')
+	    ; /* nothing */
+
+    	}
 
     (void) snprintf( buf, sizeof(buf), "RCPT TO:<%.*s>", len, recipient );
+    for (i=0; i<sizeof(buf); i++)
+    {
+	if (buf[i] == '\n')
+	    buf[i] = ' ';
+    }
     send_command( buf );
     status = read_response();
     if ( status != 250  && status != 251 )
@@ -569,7 +623,7 @@ add_recipient( char* recipient, int len 
 #endif
 
 static int
-open_client_socket( void )
+open_client_socket(const char *server, short port)
     {
 #ifdef USE_IPV6
     struct sockaddr_in6 sa;
@@ -744,10 +798,10 @@ open_client_socket( void )
 
     sockfd = socket( sock_family, sock_type, sock_protocol );
     if ( sockfd < 0 )
-	show_error( "socket" );
+	return -1;
 
     if ( connect( sockfd, (struct sockaddr*) &sa, sa_len ) < 0 )
-	show_error( "connect" );
+	return -1;
 
     return sockfd;
     }