62 |
|
|
63 |
static Socket_T S; |
static Socket_T S; |
64 |
static char *server; |
static char *server; |
65 |
|
static int did_timeout; |
66 |
static sigjmp_buf timeout; |
static sigjmp_buf timeout; |
67 |
|
|
68 |
|
|
81 |
|
|
82 |
/** |
/** |
83 |
* Send SMTP mail messages |
* Send SMTP mail messages |
84 |
* @param mail A mymail struct object |
* @param mail A Mail object |
85 |
*/ |
*/ |
86 |
void sendmail(Mail_T mail) { |
void sendmail(Mail_T mail) { |
87 |
|
|
89 |
char *now = get_RFC822date(NULL); |
char *now = get_RFC822date(NULL); |
90 |
char *localhost= get_localhostname(); |
char *localhost= get_localhostname(); |
91 |
|
|
92 |
|
ASSERT(mail); |
93 |
|
|
94 |
if(!initialize_server()) { |
if(!initialize_server()) { |
|
|
|
95 |
goto exit; |
goto exit; |
|
|
|
96 |
} |
} |
97 |
|
|
98 |
if(sigsetjmp(timeout, TRUE)) { |
if(sigsetjmp(timeout, TRUE)) { |
|
|
|
99 |
goto exit; |
goto exit; |
|
|
|
100 |
} |
} |
101 |
|
|
102 |
do_status(); |
do_status(); |
121 |
do_send("Content-Transfer-Encoding: quoted-printable\r\n"); |
do_send("Content-Transfer-Encoding: quoted-printable\r\n"); |
122 |
do_send("\r\n"); |
do_send("\r\n"); |
123 |
do_send("%s\r\n", m->message); |
do_send("%s\r\n", m->message); |
124 |
if(m->opt_message) |
if(m->opt_message) { |
125 |
do_send("%s\r\n", m->opt_message); |
do_send("%s\r\n", m->opt_message); |
126 |
|
} |
127 |
do_send(".\r\n"); |
do_send(".\r\n"); |
128 |
do_status(); |
do_status(); |
129 |
|
|
136 |
exit: |
exit: |
137 |
free(now); |
free(now); |
138 |
free(localhost); |
free(localhost); |
139 |
|
if(did_timeout) { |
140 |
|
log("Sendmail: Connection to mailserver timed out\n"); |
141 |
|
} |
142 |
finalize_server(); |
finalize_server(); |
143 |
|
|
144 |
} |
} |
152 |
struct sigaction sa; |
struct sigaction sa; |
153 |
|
|
154 |
S= NULL; |
S= NULL; |
155 |
|
did_timeout= FALSE; |
156 |
server= Run.mailserver?Run.mailserver:LOCALHOST; |
server= Run.mailserver?Run.mailserver:LOCALHOST; |
157 |
|
|
158 |
sa.sa_flags= 0; |
sa.sa_flags= 0; |
185 |
|
|
186 |
|
|
187 |
static void do_timeout(int sig) { |
static void do_timeout(int sig) { |
188 |
|
|
189 |
log("Sendmail: Connection to mailserver timed out\n"); |
did_timeout= TRUE; |
190 |
siglongjmp(timeout, TRUE); |
siglongjmp(timeout, TRUE); |
191 |
|
|
192 |
} |
} |
194 |
|
|
195 |
void do_send(const char *format, ...) { |
void do_send(const char *format, ...) { |
196 |
|
|
|
char msg[2048]; |
|
197 |
va_list ap; |
va_list ap; |
198 |
|
char msg[2048]; |
199 |
|
|
200 |
va_start(ap,format); |
va_start(ap,format); |
201 |
vsnprintf(msg, 2048, format, ap); |
vsnprintf(msg, 2048, format, ap); |