comparison src/smtp_out.c @ 177:6530806d418f

better debug logging of outgoing SMTP dialogs the dialog is logged in the style of the RFC examples: ``C: foo'' is said by the client, ``S: bar'' is said by the server debug level 4 is used, but login data is logged on level 6
author meillo@marmaro.de
date Wed, 14 Jul 2010 16:35:17 +0200
parents a39c8ee61185
children 10da50168dab
comparison
equal deleted inserted replaced
176:a39c8ee61185 177:6530806d418f
172 psb->last_code = atoi(code); 172 psb->last_code = atoi(code);
173 173
174 buf_pos += len; 174 buf_pos += len;
175 175
176 } while (code[3] == '-'); 176 } while (code[3] == '-');
177 if (psb->buffer) {
178 DEBUG(4) debugf("S: %s\n", psb->buffer);
179 }
177 180
178 return TRUE; 181 return TRUE;
179 } 182 }
180 183
181 static gboolean 184 static gboolean
292 while (TRUE) { 295 while (TRUE) {
293 if (psb->use_esmtp) { 296 if (psb->use_esmtp) {
294 fprintf(psb->out, "EHLO %s\r\n", helo); 297 fprintf(psb->out, "EHLO %s\r\n", helo);
295 fflush(psb->out); 298 fflush(psb->out);
296 299
297 DEBUG(4) debugf("EHLO %s\r\n", helo); 300 DEBUG(4) debugf("C: EHLO %s\r\n", helo);
298 301
299 } else { 302 } else {
300 fprintf(psb->out, "HELO %s\r\n", helo); 303 fprintf(psb->out, "HELO %s\r\n", helo);
301 fflush(psb->out); 304 fflush(psb->out);
302 305
303 DEBUG(4) debugf("HELO %s\r\n", helo); 306 DEBUG(4) debugf("C: HELO %s\r\n", helo);
304 307
305 } 308 }
306 309
307 if (!read_response(psb, SMTP_CMD_TIMEOUT)) 310 if (!read_response(psb, SMTP_CMD_TIMEOUT))
308 return FALSE; 311 return FALSE;
329 { 332 {
330 if (psb->use_size) { 333 if (psb->use_size) {
331 fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size); 334 fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
332 fflush(psb->out); 335 fflush(psb->out);
333 336
334 DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size); 337 DEBUG(4) debugf("C: MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
335 338
336 } else { 339 } else {
337 fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path)); 340 fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
338 fflush(psb->out); 341 fflush(psb->out);
339 342
340 DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path)); 343 DEBUG(4) debugf("C: MAIL FROM:%s\r\n", addr_string(return_path));
341 } 344 }
342 } 345 }
343 346
344 static void 347 static void
345 smtp_cmd_rcptto(smtp_base * psb, address * rcpt) 348 smtp_cmd_rcptto(smtp_base * psb, address * rcpt)
346 { 349 {
347 fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt)); 350 fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
348 fflush(psb->out); 351 fflush(psb->out);
349 DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt)); 352 DEBUG(4) debugf("C: RCPT TO:%s\n", addr_string(rcpt));
350 } 353 }
351 354
352 static void 355 static void
353 send_data_line(smtp_base * psb, gchar * data) 356 send_data_line(smtp_base * psb, gchar * data)
354 { 357 {
424 427
425 DEBUG(4) debugf("sent %d lines of data\n", num_lines); 428 DEBUG(4) debugf("sent %d lines of data\n", num_lines);
426 429
427 fprintf(psb->out, ".\r\n"); 430 fprintf(psb->out, ".\r\n");
428 fflush(psb->out); 431 fflush(psb->out);
432 DEBUG(4) debugf("C: .\n");
429 } 433 }
430 434
431 void 435 void
432 smtp_out_mark_rcpts(smtp_base * psb, GList * rcpt_list) 436 smtp_out_mark_rcpts(smtp_base * psb, GList * rcpt_list)
433 { 437 {
523 { 527 {
524 gboolean ok; 528 gboolean ok;
525 529
526 fprintf(psb->out, "RSET\r\n"); 530 fprintf(psb->out, "RSET\r\n");
527 fflush(psb->out); 531 fflush(psb->out);
528 DEBUG(4) debugf("RSET\n"); 532 DEBUG(4) debugf("C: RSET\n");
529 533
530 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) 534 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
531 if (check_response(psb, FALSE)) 535 if (check_response(psb, FALSE))
532 return TRUE; 536 return TRUE;
533 537
541 static gboolean 545 static gboolean
542 smtp_out_auth_cram_md5(smtp_base * psb) 546 smtp_out_auth_cram_md5(smtp_base * psb)
543 { 547 {
544 gboolean ok = FALSE; 548 gboolean ok = FALSE;
545 549
546 fprintf(psb->out, "AUTH CRAM-MD5\r\n"); 550 fprintf(psb->out, "C: AUTH CRAM-MD5\r\n");
547 fflush(psb->out); 551 fflush(psb->out);
548 DEBUG(4) debugf("AUTH CRAM-MD5\n"); 552 DEBUG(4) debugf("AUTH CRAM-MD5\n");
549 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) { 553 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
550 if ((ok = check_response(psb, TRUE))) { 554 if ((ok = check_response(psb, TRUE))) {
551 gchar *chall64 = get_response_arg(&(psb->buffer[4])); 555 gchar *chall64 = get_response_arg(&(psb->buffer[4]));
581 reply64 = base64_encode(reply, strlen(reply)); 585 reply64 = base64_encode(reply, strlen(reply));
582 DEBUG(5) debugf(" encoded reply = %s\n", reply64); 586 DEBUG(5) debugf(" encoded reply = %s\n", reply64);
583 587
584 fprintf(psb->out, "%s\r\n", reply64); 588 fprintf(psb->out, "%s\r\n", reply64);
585 fflush(psb->out); 589 fflush(psb->out);
586 DEBUG(4) debugf(" reply64 = %s\n", reply64); 590 DEBUG(6) debugf(" reply64 = %s\n", reply64);
591 DEBUG(6) debugf("C: %s\n", reply64);
587 592
588 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) 593 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
589 ok = check_response(psb, FALSE); 594 ok = check_response(psb, FALSE);
590 595
591 g_free(reply64); 596 g_free(reply64);
601 smtp_out_auth_login(smtp_base * psb) 606 smtp_out_auth_login(smtp_base * psb)
602 { 607 {
603 gboolean ok = FALSE; 608 gboolean ok = FALSE;
604 fprintf(psb->out, "AUTH LOGIN\r\n"); 609 fprintf(psb->out, "AUTH LOGIN\r\n");
605 fflush(psb->out); 610 fflush(psb->out);
611 DEBUG(4) debugf("C: AUTH LOGIN\r\n");
606 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) { 612 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
607 if ((ok = check_response(psb, TRUE))) { 613 if ((ok = check_response(psb, TRUE))) {
608 gchar *resp64; 614 gchar *resp64;
609 guchar *resp; 615 guchar *resp;
610 gint resp_size; 616 gint resp_size;
618 DEBUG(5) debugf(" decoded response = %s, size = %d\n", resp, resp_size); 624 DEBUG(5) debugf(" decoded response = %s, size = %d\n", resp, resp_size);
619 g_free(resp); 625 g_free(resp);
620 reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login)); 626 reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login));
621 fprintf(psb->out, "%s\r\n", reply64); 627 fprintf(psb->out, "%s\r\n", reply64);
622 fflush(psb->out); 628 fflush(psb->out);
629 DEBUG(6) debugf("C: %s\n", reply64);
623 g_free(reply64); 630 g_free(reply64);
624 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) { 631 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
625 if ((ok = check_response(psb, TRUE))) { 632 if ((ok = check_response(psb, TRUE))) {
626 resp64 = get_response_arg(&(psb->buffer[4])); 633 resp64 = get_response_arg(&(psb->buffer[4]));
627 DEBUG(5) debugf(" encoded response = %s\n", resp64); 634 DEBUG(5) debugf(" encoded response = %s\n", resp64);
630 DEBUG(5) debugf(" decoded response = %s, size = %d\n", resp, resp_size); 637 DEBUG(5) debugf(" decoded response = %s, size = %d\n", resp, resp_size);
631 g_free(resp); 638 g_free(resp);
632 reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret)); 639 reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret));
633 fprintf(psb->out, "%s\r\n", reply64); 640 fprintf(psb->out, "%s\r\n", reply64);
634 fflush(psb->out); 641 fflush(psb->out);
642 DEBUG(6) debugf("C: %s\n", reply64);
635 g_free(reply64); 643 g_free(reply64);
636 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) 644 if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
637 ok = check_response(psb, FALSE); 645 ok = check_response(psb, FALSE);
638 } 646 }
639 } 647 }
773 if (ok) { 781 if (ok) {
774 782
775 fprintf(psb->out, "DATA\r\n"); 783 fprintf(psb->out, "DATA\r\n");
776 fflush(psb->out); 784 fflush(psb->out);
777 785
778 DEBUG(4) debugf("DATA\r\n"); 786 DEBUG(4) debugf("C: DATA\r\n");
779 787
780 if (psb->use_pipelining) { 788 if (psb->use_pipelining) {
781 /* the first pl'ed command was MAIL FROM 789 /* the first pl'ed command was MAIL FROM
782 the last was DATA, whose response can be handled by the 'normal' code 790 the last was DATA, whose response can be handled by the 'normal' code
783 all in between were RCPT TO: 791 all in between were RCPT TO:
877 smtp_out_quit(smtp_base * psb) 885 smtp_out_quit(smtp_base * psb)
878 { 886 {
879 fprintf(psb->out, "QUIT\r\n"); 887 fprintf(psb->out, "QUIT\r\n");
880 fflush(psb->out); 888 fflush(psb->out);
881 889
882 DEBUG(4) debugf("QUIT\n"); 890 DEBUG(4) debugf("C: QUIT\n");
883 891
884 signal(SIGALRM, SIG_DFL); 892 signal(SIGALRM, SIG_DFL);
885 893
886 return TRUE; 894 return TRUE;
887 } 895 }