Skip to content

Commit 4dad723

Browse files
committed
win32/sendmail.c/Post(): refactor function
Change return type to bool as it only ever returns two values
1 parent 7e8c636 commit 4dad723

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

win32/sendmail.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
115115
const char *headers, char *headers_lc, char **error_message);
116116
static int MailConnect();
117117
static int PostHeader(char *RPath, const char *Subject, const char *mailTo, char *xheaders);
118-
static int Post(LPCSTR msg);
118+
static bool Post(LPCSTR msg);
119119
static int Ack(char **server_response);
120120
static unsigned long GetAddr(LPSTR szHost);
121121
static int FormatEmailAddress(char* Buf, char* EmailAddress, char* FormatString);
@@ -421,14 +421,14 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
421421

422422
/* in the beginning of the dialog */
423423
/* attempt reconnect if the first Post fail */
424-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
424+
if (!Post(PW32G(mail_buffer))) {
425425
int err = MailConnect();
426426
if (0 != err) {
427427
return (FAILED_TO_SEND);
428428
}
429429

430-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
431-
return (res);
430+
if (!Post(PW32G(mail_buffer))) {
431+
return (FAILED_TO_SEND);
432432
}
433433
}
434434
if ((res = Ack(&server_response)) != SUCCESS) {
@@ -438,8 +438,8 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
438438

439439
SMTP_SKIP_SPACE(RPath);
440440
FormatEmailAddress(PW32G(mail_buffer), RPath, "MAIL FROM:<%s>\r\n");
441-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
442-
return (res);
441+
if (!Post(PW32G(mail_buffer))) {
442+
return (FAILED_TO_SEND);
443443
}
444444
if ((res = Ack(&server_response)) != SUCCESS) {
445445
SMTP_ERROR_RESPONSE(server_response);
@@ -453,9 +453,9 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
453453
{
454454
SMTP_SKIP_SPACE(token);
455455
FormatEmailAddress(PW32G(mail_buffer), token, "RCPT TO:<%s>\r\n");
456-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
456+
if (!Post(PW32G(mail_buffer))) {
457457
efree(tempMailTo);
458-
return (res);
458+
return (FAILED_TO_SEND);
459459
}
460460
if ((res = Ack(&server_response)) != SUCCESS) {
461461
SMTP_ERROR_RESPONSE(server_response);
@@ -474,9 +474,9 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
474474
{
475475
SMTP_SKIP_SPACE(token);
476476
FormatEmailAddress(PW32G(mail_buffer), token, "RCPT TO:<%s>\r\n");
477-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
477+
if (!Post(PW32G(mail_buffer))) {
478478
efree(tempMailTo);
479-
return (res);
479+
return (FAILED_TO_SEND);
480480
}
481481
if ((res = Ack(&server_response)) != SUCCESS) {
482482
SMTP_ERROR_RESPONSE(server_response);
@@ -514,9 +514,9 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
514514
{
515515
SMTP_SKIP_SPACE(token);
516516
FormatEmailAddress(PW32G(mail_buffer), token, "RCPT TO:<%s>\r\n");
517-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
517+
if (!Post(PW32G(mail_buffer))) {
518518
efree(tempMailTo);
519-
return (res);
519+
return (FAILED_TO_SEND);
520520
}
521521
if ((res = Ack(&server_response)) != SUCCESS) {
522522
SMTP_ERROR_RESPONSE(server_response);
@@ -539,9 +539,9 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
539539
{
540540
SMTP_SKIP_SPACE(token);
541541
FormatEmailAddress(PW32G(mail_buffer), token, "RCPT TO:<%s>\r\n");
542-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
542+
if (!Post(PW32G(mail_buffer))) {
543543
efree(tempMailTo);
544-
return (res);
544+
return (FAILED_TO_SEND);
545545
}
546546
if ((res = Ack(&server_response)) != SUCCESS) {
547547
SMTP_ERROR_RESPONSE(server_response);
@@ -587,9 +587,9 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
587587
{
588588
SMTP_SKIP_SPACE(token);
589589
FormatEmailAddress(PW32G(mail_buffer), token, "RCPT TO:<%s>\r\n");
590-
if ((res = Post(PW32G(mail_buffer))) != SUCCESS) {
590+
if (!Post(PW32G(mail_buffer))) {
591591
efree(tempMailTo);
592-
return (res);
592+
return (FAILED_TO_SEND);
593593
}
594594
if ((res = Ack(&server_response)) != SUCCESS) {
595595
SMTP_ERROR_RESPONSE(server_response);
@@ -625,11 +625,11 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
625625
stripped_header = estrndup(headers, strlen(headers));
626626
}
627627

628-
if ((res = Post("DATA\r\n")) != SUCCESS) {
628+
if (!Post("DATA\r\n")) {
629629
if (stripped_header) {
630630
efree(stripped_header);
631631
}
632-
return (res);
632+
return (FAILED_TO_SEND);
633633
}
634634
if ((res = Ack(&server_response)) != SUCCESS) {
635635
SMTP_ERROR_RESPONSE(server_response);
@@ -670,24 +670,24 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
670670
e2 = p + 1024;
671671
c = *e2;
672672
*e2 = '\0';
673-
if ((res = Post(p)) != SUCCESS) {
673+
if (!Post(p)) {
674674
zend_string_free(data_cln);
675-
return(res);
675+
return(FAILED_TO_SEND);
676676
}
677677
*e2 = c;
678678
p = e2;
679679
}
680-
if ((res = Post(p)) != SUCCESS) {
680+
if (!Post(p)) {
681681
zend_string_free(data_cln);
682-
return(res);
682+
return(FAILED_TO_SEND);
683683
}
684684
}
685685

686686
zend_string_free(data_cln);
687687

688688
/*send termination dot */
689-
if ((res = Post("\r\n.\r\n")) != SUCCESS)
690-
return (res);
689+
if (!Post("\r\n.\r\n"))
690+
return (FAILED_TO_SEND);
691691
if ((res = Ack(&server_response)) != SUCCESS) {
692692
SMTP_ERROR_RESPONSE(server_response);
693693
return (res);
@@ -771,14 +771,14 @@ static int PostHeader(char *RPath, const char *Subject, const char *mailTo, char
771771
if (headers_lc) {
772772
efree(headers_lc);
773773
}
774-
if ((res = Post(header_buffer)) != SUCCESS) {
774+
if (!Post(header_buffer)) {
775775
efree(header_buffer);
776-
return (res);
776+
return (FAILED_TO_SEND);
777777
}
778778
efree(header_buffer);
779779

780-
if ((res = Post("\r\n")) != SUCCESS) {
781-
return (res);
780+
if (!Post("\r\n")) {
781+
return (FAILED_TO_SEND);
782782
}
783783

784784
return (SUCCESS);
@@ -896,7 +896,7 @@ return 0;
896896
// Author/Date: jcar 20/9/96
897897
// History:
898898
//*********************************************************************
899-
static int Post(LPCSTR msg)
899+
static bool Post(LPCSTR msg)
900900
{
901901
int len = (int)strlen(msg);
902902
int slen;
@@ -905,16 +905,16 @@ static int Post(LPCSTR msg)
905905
#if SENDMAIL_DEBUG
906906
if (msg)
907907
printf("POST: '%s'\n", msg);
908-
return (SUCCESS);
908+
return true;
909909
#endif
910910

911911
while (len > 0) {
912912
if ((slen = send(PW32G(mail_socket), msg + index, len, 0)) < 1)
913-
return (FAILED_TO_SEND);
913+
return false;
914914
len -= slen;
915915
index += slen;
916916
}
917-
return (SUCCESS);
917+
return true;
918918
}
919919

920920

0 commit comments

Comments
 (0)