From 683948a174fd2d4e8222857226330202744bdce7 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Fri, 1 Jul 2005 06:13:59 +0000 Subject: [PATCH] bug fix: insert content-type header in message if missing, try and guess what it should be by examining message body --- mbuni/mmlib/mms_msg.c | 17 ++++++++++++++++- mbuni/mmlib/mms_util.c | 8 ++++---- mbuni/mmlib/mms_util.h | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mbuni/mmlib/mms_msg.c b/mbuni/mmlib/mms_msg.c index e39438e..fd1b291 100644 --- a/mbuni/mmlib/mms_msg.c +++ b/mbuni/mmlib/mms_msg.c @@ -1012,7 +1012,22 @@ static int fixup_msg(MmsMsg *m, Octstr *from) http_header_add(m->headers, "MessageID", "00000"); else octstr_destroy(s); - + + /* check for content-type. */ + if ((s = http_header_value(m->headers, octstr_imm("Content-Type"))) == NULL) { + char *ctype; + if (m->body.s == NULL || + (!m->ismultipart && + octstr_check_range(m->body.s, 0, + octstr_len(m->body.s), _mms_gw_isprint) == 0)) + ctype = "application/octet-stream"; + else if (m->ismultipart) + ctype = "application/vnd.wap.multipart.mixed"; + else + ctype = "text/plain"; + http_header_add(m->headers, "Content-Type", ctype); + } else + octstr_destroy(s); } return 0; diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index c35d557..08dbb7b 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -726,12 +726,12 @@ void unbase64_mimeparts(MIMEEntity *m) octstr_destroy(te); } } -#if 1 -static int gw_isprint(int c) + +int _mms_gw_isprint(int c) { return isprint(c) || isspace(c); } -#endif + /* Change content coding for mime entities that need it. */ void base64_mimeparts(MIMEEntity *m) @@ -748,7 +748,7 @@ void base64_mimeparts(MIMEEntity *m) if (ctype && !te #if 1 && - (m->body && octstr_check_range(m->body, 0, octstr_len(m->body), gw_isprint) == 0) + (m->body && octstr_check_range(m->body, 0, octstr_len(m->body), _mms_gw_isprint) == 0) #endif ) { octstr_binary_to_base64(m->body); diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index 02869e4..8f124ea 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -206,4 +206,7 @@ int mm_lockfile(int fd, char *fname, int shouldblock); /* This should be elsewhere, but it isn't, so we do it here... */ extern MIMEEntity *mime_entity_duplicate(MIMEEntity *m); + +/* Returns true if the character is printable or space */ +int _mms_gw_isprint(int c); #endif