Skip to content

Commit 0295f2e

Browse files
committed
Refactor imap_mail()'s internal implementation to use zend_strings
1 parent 048cc9b commit 0295f2e

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

ext/imap/php_imap.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,8 @@ PHP_FUNCTION(imap_mail_compose)
34113411
/* }}} */
34123412

34133413
/* {{{ _php_imap_mail */
3414-
int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *cc, char *bcc, char* rpath)
3414+
bool _php_imap_mail(zend_string *to, zend_string *subject, zend_string *message, zend_string *headers,
3415+
zend_string *cc, zend_string *bcc, zend_string* rpath)
34153416
{
34163417
#ifdef PHP_WIN32
34173418
int tsm_err;
@@ -3429,13 +3430,13 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
34293430
size_t bt_len;
34303431

34313432
if (headers) {
3432-
bufferLen += strlen(headers);
3433+
bufferLen += ZSTR_LEN(headers);
34333434
}
34343435
if (to) {
3435-
bufferLen += strlen(to) + 6;
3436+
bufferLen += ZSTR_LEN(to) + 6;
34363437
}
34373438
if (cc) {
3438-
bufferLen += strlen(cc) + 6;
3439+
bufferLen += ZSTR_LEN(cc) + 6;
34393440
}
34403441

34413442
#define PHP_IMAP_CLEAN if (bufferTo) efree(bufferTo); if (bufferCc) efree(bufferCc); if (bufferBcc) efree(bufferBcc); if (bufferHeader) efree(bufferHeader);
@@ -3445,10 +3446,10 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
34453446
memset(bufferHeader, 0, bufferLen);
34463447
if (to && *to) {
34473448
strlcat(bufferHeader, "To: ", bufferLen + 1);
3448-
strlcat(bufferHeader, to, bufferLen + 1);
3449+
strlcat(bufferHeader, ZSTR_VAL(to), bufferLen + 1);
34493450
strlcat(bufferHeader, "\r\n", bufferLen + 1);
3450-
tempMailTo = estrdup(to);
3451-
bt_len = strlen(to);
3451+
tempMailTo = estrdup(ZSTR_VAL(to));
3452+
bt_len = ZSTR_LEN(to);
34523453
bufferTo = (char *)safe_emalloc(bt_len, 1, 1);
34533454
bt_len++;
34543455
offset = 0;
@@ -3474,10 +3475,10 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
34743475

34753476
if (cc && *cc) {
34763477
strlcat(bufferHeader, "Cc: ", bufferLen + 1);
3477-
strlcat(bufferHeader, cc, bufferLen + 1);
3478+
strlcat(bufferHeader, ZSTR_VAL(cc), bufferLen + 1);
34783479
strlcat(bufferHeader, "\r\n", bufferLen + 1);
3479-
tempMailTo = estrdup(cc);
3480-
bt_len = strlen(cc);
3480+
tempMailTo = estrdup(ZSTR_VAL(cc));
3481+
bt_len = ZSTR_LEN(cc);
34813482
bufferCc = (char *)safe_emalloc(bt_len, 1, 1);
34823483
bt_len++;
34833484
offset = 0;
@@ -3502,8 +3503,8 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
35023503
}
35033504

35043505
if (bcc && *bcc) {
3505-
tempMailTo = estrdup(bcc);
3506-
bt_len = strlen(bcc);
3506+
tempMailTo = estrdup(ZSTR_VAL(bcc));
3507+
bt_len = ZSTR_LEN(bcc);
35073508
bufferBcc = (char *)safe_emalloc(bt_len, 1, 1);
35083509
bt_len++;
35093510
offset = 0;
@@ -3528,10 +3529,11 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
35283529
}
35293530

35303531
if (headers && *headers) {
3531-
strlcat(bufferHeader, headers, bufferLen + 1);
3532+
strlcat(bufferHeader, ZSTR_VAL(headers), bufferLen + 1);
35323533
}
35333534

3534-
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
3535+
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, ZSTR_VAL(subject),
3536+
bufferTo, ZSTR_VAL(message), bufferCc, bufferBcc, ZSTR_VAL(rpath)) != SUCCESS) {
35353537
if (tsm_errmsg) {
35363538
php_error_docref(NULL, E_WARNING, "%s", tsm_errmsg);
35373539
efree(tsm_errmsg);
@@ -3548,15 +3550,15 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
35483550
}
35493551
sendmail = popen(INI_STR("sendmail_path"), "w");
35503552
if (sendmail) {
3551-
if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath);
3552-
fprintf(sendmail, "To: %s\n", to);
3553-
if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc);
3554-
if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc);
3555-
fprintf(sendmail, "Subject: %s\n", subject);
3553+
if (ZSTR_LEN(rpath) != 0) fprintf(sendmail, "From: %s\n", ZSTR_VAL(rpath));
3554+
fprintf(sendmail, "To: %s\n", ZSTR_VAL(to));
3555+
if (ZSTR_LEN(cc) != 0) fprintf(sendmail, "Cc: %s\n", ZSTR_VAL(cc));
3556+
if (ZSTR_LEN(bcc) != 0) fprintf(sendmail, "Bcc: %s\n", ZSTR_VAL(bcc));
3557+
fprintf(sendmail, "Subject: %s\n", ZSTR_VAL(subject));
35563558
if (headers != NULL) {
3557-
fprintf(sendmail, "%s\n", headers);
3559+
fprintf(sendmail, "%s\n", ZSTR_VAL(headers));
35583560
}
3559-
fprintf(sendmail, "\n%s\n", message);
3561+
fprintf(sendmail, "\n%s\n", ZSTR_VAL(message));
35603562
ret = pclose(sendmail);
35613563

35623564
return ret != -1;
@@ -3598,8 +3600,7 @@ PHP_FUNCTION(imap_mail)
35983600
php_error_docref(NULL, E_WARNING, "No message string in mail command");
35993601
}
36003602

3601-
if (_php_imap_mail(ZSTR_VAL(to), ZSTR_VAL(subject), ZSTR_VAL(message), headers?ZSTR_VAL(headers):NULL, cc?ZSTR_VAL(cc):NULL,
3602-
bcc?ZSTR_VAL(bcc):NULL, rpath?ZSTR_VAL(rpath):NULL)) {
3603+
if (_php_imap_mail(to, subject, message, headers, cc, bcc, rpath)) {
36033604
RETURN_TRUE;
36043605
} else {
36053606
RETURN_FALSE;

0 commit comments

Comments
 (0)