提交 29f66f99 authored 作者: Anthony Minessale's avatar Anthony Minessale

doh

上级 7471ec17
...@@ -604,17 +604,8 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, ...@@ -604,17 +604,8 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
char *newfile = NULL; char *newfile = NULL;
switch_bool_t rval = SWITCH_FALSE; switch_bool_t rval = SWITCH_FALSE;
const char *err = NULL; const char *err = NULL;
const char *stipped_file;
const char *new_type;
char *xext;
if (zstr(file)) { if (!zstr(file) && !zstr(convert_cmd) && !zstr(convert_ext)) {
err = "Missing file";
rval = SWITCH_FALSE;
goto end;
}
if (!zstr(convert_cmd) && !zstr(convert_ext)) {
if ((ext = strrchr(file, '.'))) { if ((ext = strrchr(file, '.'))) {
dupfile = strdup(file); dupfile = strdup(file);
if ((ext = strrchr(dupfile, '.'))) { if ((ext = strrchr(dupfile, '.'))) {
...@@ -639,118 +630,120 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, ...@@ -639,118 +630,120 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int) switch_epoch_time_now(NULL), rand() & 0xffff); switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int) switch_epoch_time_now(NULL), rand() & 0xffff);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) {
err = "Failed to open temp file"; if (file) {
rval = SWITCH_FALSE; if ((ifd = open(file, O_RDONLY | O_BINARY)) < 0) {
goto end; rval = SWITCH_FALSE;
} err = "Cannot open tmp file\n";
goto end;
if ((ifd = open(file, O_RDONLY | O_BINARY)) < 0) { }
rval = SWITCH_FALSE; }
err = "Failed to open source file\n"; switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
goto end; if (!write_buf(fd, buf)) {
} rval = SWITCH_FALSE;
err = "write error.";
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound); goto end;
if (!write_buf(fd, buf)) { }
rval = SWITCH_FALSE;
err = "write error.";
goto end;
}
if (headers && !write_buf(fd, headers)) {
rval = SWITCH_FALSE;
err = "write error.";
goto end;
}
if (!write_buf(fd, "\n\n")) {
rval = SWITCH_FALSE;
err = "write error.";
goto end;
}
if (body && switch_stristr("content-type", body)) { if (headers && !write_buf(fd, headers)) {
switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound); rval = SWITCH_FALSE;
} else { err = "write error.";
switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound); goto end;
} }
if (!write_buf(fd, buf)) {
rval = SWITCH_FALSE;
err = "write error.";
goto end;
}
if (body) { if (!write_buf(fd, "\n\n")) {
if (!write_buf(fd, body)) {
rval = SWITCH_FALSE; rval = SWITCH_FALSE;
err = "write error."; err = "write error.";
goto end; goto end;
} }
}
stipped_file = switch_cut_path(file); if (body && switch_stristr("content-type", body)) {
switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound);
} else {
switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
}
if (!write_buf(fd, buf)) {
rval = SWITCH_FALSE;
err = "write error.";
goto end;
}
if ((xext = strrchr(stipped_file, '.'))) { if (body) {
xext++; if (!write_buf(fd, body)) {
if ((new_type = switch_core_mime_ext2type(xext))) { rval = SWITCH_FALSE;
mime_type = new_type; err = "write error.";
goto end;
}
} }
}
switch_snprintf(buf, B64BUFFLEN, if (file) {
"\n\n--%s\nContent-Type: %s; name=\"%s\"\n" const char *stipped_file = switch_cut_path(file);
"Content-ID: <ATTACHED@freeswitch.org>\n" const char *new_type;
"Content-Transfer-Encoding: base64\n" char *ext;
"Content-Description: Sound attachment.\n"
"Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file); if ((ext = strrchr(stipped_file, '.'))) {
if (!write_buf(fd, buf)) { ext++;
rval = SWITCH_FALSE; if ((new_type = switch_core_mime_ext2type(ext))) {
err = "write error."; mime_type = new_type;
goto end; }
} }
while ((ilen = read(ifd, in, B64BUFFLEN))) { switch_snprintf(buf, B64BUFFLEN,
for (x = 0; x < ilen; x++) { "\n\n--%s\nContent-Type: %s; name=\"%s\"\n"
b = (b << 8) + in[x]; "Content-ID: <ATTACHED@freeswitch.org>\n"
l += 8; "Content-Transfer-Encoding: base64\n"
while (l >= 6) { "Content-Description: Sound attachment.\n"
out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64]; "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
if (++y != 72) if (!write_buf(fd, buf)) {
continue; rval = SWITCH_FALSE;
out[bytes++] = '\n'; err = "write error.";
y = 0; goto end;
} }
}
if (write(fd, &out, bytes) != bytes) {
rval = -1;
break;
} else {
bytes = 0;
}
} while ((ilen = read(ifd, in, B64BUFFLEN))) {
for (x = 0; x < ilen; x++) {
b = (b << 8) + in[x];
l += 8;
while (l >= 6) {
out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64];
if (++y != 72)
continue;
out[bytes++] = '\n';
y = 0;
}
}
if (write(fd, &out, bytes) != bytes) {
rval = -1;
break;
} else {
bytes = 0;
}
if (l > 0) { }
out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64];
} if (l > 0) {
out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64];
}
if (l != 0)
while (l < 6) {
out[bytes++] = '=', l += 2;
}
if (write(fd, &out, bytes) != bytes) {
rval = -1;
}
if (l != 0)
while (l < 6) {
out[bytes++] = '=', l += 2;
} }
if (write(fd, &out, bytes) != bytes) {
rval = -1;
}
switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound); switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
if (!write_buf(fd, buf)) { if (!write_buf(fd, buf)) {
rval = SWITCH_FALSE; rval = SWITCH_FALSE;
err = "write error."; err = "write error.";
goto end; goto end;
}
} }
if (zstr(from)) { if (zstr(from)) {
from = "freeswitch"; from = "freeswitch";
} }
...@@ -781,13 +774,14 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, ...@@ -781,13 +774,14 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
end: end:
if (fd > -1) { if (fd < 0) {
close(fd); close(fd);
} }
if (ifd > -1) { if (ifd < 0) {
close(ifd); close(ifd);
} }
if (newfile) { if (newfile) {
unlink(newfile); unlink(newfile);
free(newfile); free(newfile);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论