From 498d8851337eba448faab1da4dc926a862958406 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Wed, 31 Mar 2010 19:09:46 +0000 Subject: [PATCH] Ensure line terminators in email are consistent. Fixes an issue with certain Mail Transport Agents, where attachments are not interpreted correctly. (closes issue #16557) Reported by: jcovert Patches: 20100308__issue16557__1.4.diff.txt uploaded by tilghman (license 14) 20100308__issue16557__1.6.0.diff.txt uploaded by tilghman (license 14) 20100308__issue16557__trunk.diff.txt uploaded by tilghman (license 14) Tested by: ebroad, zktech Reviewboard: https://reviewboard.asterisk.org/r/544/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@255591 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_voicemail.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 4fa755417e..ba1e6b63d2 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -185,7 +185,11 @@ static struct vmstate *vmstates = NULL; #define BASEMAXINLINE 256 #define BASELINELEN 72 #define BASEMAXINLINE 256 -#define eol "\r\n" +#ifdef IMAP_STORAGE +#define ENDL "\r\n" +#else +#define ENDL "\n" +#endif #define MAX_DATETIME_FORMAT 512 #define MAX_NUM_CID_CONTEXTS 10 @@ -2980,15 +2984,17 @@ static int inchar(struct baseio *bio, FILE *fi) static int ochar(struct baseio *bio, int c, FILE *so) { - if (bio->linelength>=BASELINELEN) { - if (fputs(eol,so)==EOF) + if (bio->linelength >= BASELINELEN) { + if (fputs(ENDL, so) == EOF) { return -1; + } - bio->linelength= 0; + bio->linelength = 0; } - if (putc(((unsigned char)c),so)==EOF) + if (putc(((unsigned char) c), so) == EOF) { return -1; + } bio->linelength++; @@ -3061,8 +3067,9 @@ static int base_encode(char *filename, FILE *so) fclose(fi); - if (fputs(eol,so)==EOF) + if (fputs(ENDL, so) == EOF) { return 0; + } return 1; } @@ -3236,11 +3243,6 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in struct tm tm; char *passdata = NULL, *passdata2; size_t len_passdata = 0, len_passdata2, tmplen; -#ifdef IMAP_STORAGE -#define ENDL "\r\n" -#else -#define ENDL "\n" -#endif /* One alloca for multiple fields */ len_passdata2 = strlen(vmu->fullname); @@ -3404,7 +3406,22 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in memset(passdata, 0, vmlen); prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, fromfolder, cidnum, cidname, dur, date, passdata, vmlen, category); pbx_substitute_variables_helper(ast, emailbody, passdata, vmlen); +#ifdef IMAP_STORAGE + { + /* Convert body to native line terminators for IMAP backend */ + char *line = passdata, *next; + do { + /* Terminate line before outputting it to the file */ + if ((next = strchr(line, '\n'))) { + *next++ = '\0'; + } + fprintf(p, "%s" ENDL, line); + line = next; + } while (!ast_strlen_zero(line)); + } +#else fprintf(p, "%s" ENDL, passdata); +#endif } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n"); ast_channel_free(ast); @@ -3497,8 +3514,8 @@ plain_message: unlink(newtmp); } } -#undef ENDL } + static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *fromfolder, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category) { FILE *p=NULL;