add printed errors to mailer
This commit is contained in:
parent
cde54eb5e8
commit
0b21064a05
|
@ -603,6 +603,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
char *dupfile = NULL, *ext = NULL;
|
char *dupfile = NULL, *ext = NULL;
|
||||||
char *newfile = NULL;
|
char *newfile = NULL;
|
||||||
switch_bool_t rval = SWITCH_FALSE;
|
switch_bool_t rval = SWITCH_FALSE;
|
||||||
|
const char *err = NULL;
|
||||||
|
|
||||||
if (!zstr(file) && !zstr(convert_cmd) && !zstr(convert_ext)) {
|
if (!zstr(file) && !zstr(convert_cmd) && !zstr(convert_ext)) {
|
||||||
if ((ext = strrchr(file, '.'))) {
|
if ((ext = strrchr(file, '.'))) {
|
||||||
|
@ -633,22 +634,26 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
if (file) {
|
if (file) {
|
||||||
if ((ifd = open(file, O_RDONLY | O_BINARY)) < 1) {
|
if ((ifd = open(file, O_RDONLY | O_BINARY)) < 1) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "Cannot open tmp file\n";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
|
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
|
||||||
if (!write_buf(fd, buf)) {
|
if (!write_buf(fd, buf)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers && !write_buf(fd, headers)) {
|
if (headers && !write_buf(fd, headers)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!write_buf(fd, "\n\n")) {
|
if (!write_buf(fd, "\n\n")) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,12 +664,14 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
}
|
}
|
||||||
if (!write_buf(fd, buf)) {
|
if (!write_buf(fd, buf)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
if (!write_buf(fd, body)) {
|
if (!write_buf(fd, body)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -689,6 +696,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
"Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
|
"Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
|
||||||
if (!write_buf(fd, buf)) {
|
if (!write_buf(fd, buf)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,6 +738,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
|
|
||||||
if (!write_buf(fd, buf)) {
|
if (!write_buf(fd, buf)) {
|
||||||
rval = SWITCH_FALSE;
|
rval = SWITCH_FALSE;
|
||||||
|
err = "write error.";
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -751,19 +760,23 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
#endif
|
#endif
|
||||||
if (switch_system(buf, SWITCH_TRUE) < 0) {
|
if (switch_system(buf, SWITCH_TRUE) < 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
|
||||||
|
err = "execute error";
|
||||||
|
rval = SWITCH_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(filename) != 0) {
|
if (unlink(filename) != 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", filename);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
if (zstr(err)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
|
if (file) {
|
||||||
} else {
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
|
} else {
|
||||||
}
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
|
||||||
|
}
|
||||||
|
|
||||||
rval = SWITCH_TRUE;
|
rval = SWITCH_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
|
@ -772,6 +785,12 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
|
||||||
free(newfile);
|
free(newfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rval != SWITCH_TRUE) {
|
||||||
|
if (zstr(err)) err = "Unknown Error";
|
||||||
|
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "EMAIL NOT SENT, error [%s]\n", err);
|
||||||
|
}
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue