-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Imap send #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imap send #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4016,18 +4016,64 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * | |
if (!INI_STR("sendmail_path")) { | ||
return 0; | ||
} | ||
sendmail = popen(INI_STR("sendmail_path"), "w"); | ||
|
||
char *sendmail_path = INI_STR("sendmail_path"); | ||
char *appended_sendmail_path = NULL; | ||
int rpath_length = strlen(rpath); | ||
int sendmail_length = strlen(sendmail_path); | ||
char *force_extra_parameters = INI_STR("mail.force_extra_parameters"); | ||
char *extra_cmd = NULL; | ||
|
||
if (force_extra_parameters) { | ||
extra_cmd = php_escape_shell_cmd(force_extra_parameters); | ||
} | ||
|
||
if (rpath && rpath[0]) { | ||
appended_sendmail_path = emalloc(sendmail_length + 3 + rpath_length + 1); | ||
strncpy(appended_sendmail_path, sendmail_path, 50); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does the 50 come from? |
||
strncat(appended_sendmail_path, " -f", 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the magic constant 3 one might use sizeof(" -f")-1. If the above magic 50 is fixed one might probably calculate the offset in append_sendmail_path and use strncpy here, too |
||
strncat(appended_sendmail_path, rpath, rpath_length); | ||
sendmail_path = appended_sendmail_path; | ||
} | ||
|
||
if (extra_cmd) { | ||
spprintf(&sendmail_path, 0, "%s %s", sendmail_path, extra_cmd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this change INI_STR("sendmail_path")? (at least if !rpath || !rpath[0] ) |
||
} | ||
|
||
sendmail = popen(sendmail_path, "w"); | ||
|
||
if (appended_sendmail_path) { | ||
efree(appended_sendmail_path); | ||
} | ||
|
||
if (extra_cmd) { | ||
efree(extra_cmd); | ||
} | ||
|
||
if (sendmail) { | ||
if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath); | ||
if (rpath && rpath[0]) { | ||
fprintf(sendmail, "From: %s\n", rpath); | ||
} | ||
|
||
fprintf(sendmail, "To: %s\n", to); | ||
if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc); | ||
if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc); | ||
|
||
if (cc && cc[0]) { | ||
fprintf(sendmail, "Cc: %s\n", cc); | ||
} | ||
|
||
if (bcc && bcc[0]) { | ||
fprintf(sendmail, "Bcc: %s\n", bcc); | ||
} | ||
|
||
fprintf(sendmail, "Subject: %s\n", subject); | ||
|
||
if (headers != NULL) { | ||
fprintf(sendmail, "%s\n", headers); | ||
} | ||
|
||
fprintf(sendmail, "\n%s\n", message); | ||
ret = pclose(sendmail); | ||
|
||
if (ret == -1) { | ||
return 0; | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declarations have to go first in the block to be compliant with ANSI C. Either move the declarations up or put this in a block.