minor adj

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5851 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-10-12 17:12:31 +00:00
parent 96628675b5
commit 0a980a4ff9
6 changed files with 143 additions and 135 deletions
+129
View File
@@ -68,6 +68,135 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size
}
static int write_buf(int fd, char *buf)
{
int len = (int) strlen(buf);
if (fd && write(fd, buf, len) != len) {
close(fd);
return 0;
}
return 1;
}
SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *headers, char *body, char *file)
{
char *bound = "XXXX_boundary_XXXX";
char filename[80], buf[B64BUFFLEN];
int fd = 0, ifd = 0;
int x = 0, y = 0, bytes = 0, ilen = 0;
unsigned int b = 0, l = 0;
unsigned char in[B64BUFFLEN];
unsigned char out[B64BUFFLEN + 512];
char *path = NULL;
snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
if (file) {
path = file;
if ((ifd = open(path, O_RDONLY)) < 1) {
return SWITCH_FALSE;
}
snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
if (!write_buf(fd, buf)) {
return SWITCH_FALSE;
}
}
if (headers && !write_buf(fd, headers))
return SWITCH_FALSE;
if (!write_buf(fd, "\n\n"))
return SWITCH_FALSE;
if (file) {
snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
if (!write_buf(fd, buf))
return SWITCH_FALSE;
}
if (body) {
if (!write_buf(fd, body)) {
return SWITCH_FALSE;
}
}
if (file) {
snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
"Content-Transfer-Encoding: base64\n"
"Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, switch_cut_path(file));
if (!write_buf(fd, buf))
return SWITCH_FALSE;
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) {
return -1;
} else
bytes = 0;
}
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) {
return -1;
}
}
if (file) {
snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
if (!write_buf(fd, buf))
return SWITCH_FALSE;
}
}
if (fd) {
close(fd);
}
if (ifd) {
close(ifd);
}
snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to);
if(system(buf)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
}
unlink(filename);
if (file) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
}
return SWITCH_TRUE;
}
SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int family)
{
switch_status_t status = SWITCH_STATUS_FALSE;