Misc. code movements
This commit is contained in:
parent
f67330f9e0
commit
0d2974bd27
|
@ -2564,3 +2564,80 @@ void mygw_free(void *x)
|
|||
{
|
||||
gw_free(x);
|
||||
}
|
||||
|
||||
|
||||
/* Finds text part, returns copy. */
|
||||
static MIMEEntity *find_textpart(MIMEEntity *m)
|
||||
{
|
||||
Octstr *ctype = NULL, *params = NULL;
|
||||
MIMEEntity *res = NULL;
|
||||
List *headers;
|
||||
int i, n;
|
||||
|
||||
if (!m) return NULL;
|
||||
|
||||
headers = mime_entity_headers(m);
|
||||
get_content_type(headers, &ctype, ¶ms);
|
||||
http_destroy_headers(headers);
|
||||
|
||||
if (ctype && octstr_str_compare(ctype, "text/plain") == 0) {
|
||||
res = mime_entity_duplicate(m);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((n = mime_entity_num_parts(m)) > 0) {
|
||||
for (i = 0; i < n; i++) {
|
||||
MIMEEntity *x = mime_entity_get_part(m, i);
|
||||
res = find_textpart(x);
|
||||
mime_entity_destroy(x);
|
||||
|
||||
if (res != NULL)
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (res) { /* We got it! Convert charset if needed. */
|
||||
List *params_h = get_value_parameters(params);
|
||||
Octstr *charset = http_header_value(params_h, octstr_imm("charset"));
|
||||
Octstr *body = mime_entity_body(res);
|
||||
if (charset == NULL ||
|
||||
octstr_str_compare(charset, "unknown") == 0) {
|
||||
octstr_destroy(charset);
|
||||
charset = octstr_create(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
if (octstr_str_case_compare(charset, DEFAULT_CHARSET) != 0) {
|
||||
charset_convert(body, DEFAULT_CHARSET, octstr_get_cstr(charset)); /* XXX error ignored? */
|
||||
mime_entity_set_body(res, body);
|
||||
}
|
||||
octstr_destroy(body);
|
||||
http_destroy_headers(params_h);
|
||||
octstr_destroy(charset);
|
||||
}
|
||||
|
||||
done2:
|
||||
|
||||
octstr_destroy(ctype);
|
||||
octstr_destroy(params);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* Gets the keyword, if any, from the text part of the message.
|
||||
* converts charset as needed.
|
||||
*/
|
||||
Octstr *get_keyword_from_mime(MIMEEntity *me)
|
||||
{
|
||||
|
||||
MIMEEntity *t = find_textpart(me);
|
||||
Octstr *txt = t ? mime_entity_body(t) : NULL;
|
||||
List *l = t ? octstr_split_words(txt) : NULL;
|
||||
Octstr *keyword = l ? gwlist_extract_first(l) : NULL;
|
||||
|
||||
if (t)
|
||||
mime_entity_destroy(t);
|
||||
gwlist_destroy(l, (gwlist_item_destructor_t *)octstr_destroy);
|
||||
octstr_destroy(txt);
|
||||
|
||||
return keyword;
|
||||
}
|
||||
|
|
|
@ -264,6 +264,8 @@ Octstr *parse_rfc2047_text(Octstr *in, int *mibenum);
|
|||
/* Utility func */
|
||||
void mygw_free(void *);
|
||||
|
||||
/* Get (copy of) keyword from mime thingie */
|
||||
Octstr *get_keyword_from_mime(MIMEEntity *me);
|
||||
#define US_ASCII_MIB_VAL 3
|
||||
#define UTF8_MIB_VAL 106
|
||||
|
||||
|
@ -292,4 +294,5 @@ List *gwlist_create_ex_real(const char *file, const char *func, int line,...);
|
|||
(res) = __res; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,82 +48,6 @@ static void relog_now(int notused)
|
|||
alog_reopen();
|
||||
}
|
||||
|
||||
/* Finds text part, returns copy. */
|
||||
static MIMEEntity *find_textpart(MIMEEntity *m)
|
||||
{
|
||||
Octstr *ctype = NULL, *params = NULL;
|
||||
MIMEEntity *res = NULL;
|
||||
List *headers;
|
||||
int i, n;
|
||||
|
||||
if (!m) return NULL;
|
||||
|
||||
headers = mime_entity_headers(m);
|
||||
get_content_type(headers, &ctype, ¶ms);
|
||||
http_destroy_headers(headers);
|
||||
|
||||
if (ctype && octstr_str_compare(ctype, "text/plain") == 0) {
|
||||
res = mime_entity_duplicate(m);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((n = mime_entity_num_parts(m)) > 0) {
|
||||
for (i = 0; i < n; i++) {
|
||||
MIMEEntity *x = mime_entity_get_part(m, i);
|
||||
res = find_textpart(x);
|
||||
mime_entity_destroy(x);
|
||||
|
||||
if (res != NULL)
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (res) { /* We got it! Convert charset if needed. */
|
||||
List *params_h = get_value_parameters(params);
|
||||
Octstr *charset = http_header_value(params_h, octstr_imm("charset"));
|
||||
Octstr *body = mime_entity_body(res);
|
||||
if (charset == NULL ||
|
||||
octstr_str_compare(charset, "unknown") == 0) {
|
||||
octstr_destroy(charset);
|
||||
charset = octstr_create(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
if (octstr_str_case_compare(charset, DEFAULT_CHARSET) != 0) {
|
||||
charset_convert(body, DEFAULT_CHARSET, octstr_get_cstr(charset)); /* XXX error ignored? */
|
||||
mime_entity_set_body(res, body);
|
||||
}
|
||||
octstr_destroy(body);
|
||||
http_destroy_headers(params_h);
|
||||
octstr_destroy(charset);
|
||||
}
|
||||
|
||||
done2:
|
||||
|
||||
octstr_destroy(ctype);
|
||||
octstr_destroy(params);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* Gets the keyword, if any, from the text part of the message.
|
||||
* converts charset as needed.
|
||||
*/
|
||||
static Octstr *get_keyword(MIMEEntity *me)
|
||||
{
|
||||
|
||||
MIMEEntity *t = find_textpart(me);
|
||||
Octstr *txt = t ? mime_entity_body(t) : NULL;
|
||||
List *l = t ? octstr_split_words(txt) : NULL;
|
||||
Octstr *keyword = l ? gwlist_extract_first(l) : NULL;
|
||||
|
||||
if (t)
|
||||
mime_entity_destroy(t);
|
||||
gwlist_destroy(l, (gwlist_item_destructor_t *)octstr_destroy);
|
||||
octstr_destroy(txt);
|
||||
|
||||
return keyword;
|
||||
}
|
||||
|
||||
static int _x_octstr_comp(Octstr *x, Octstr *y)
|
||||
{
|
||||
return (octstr_case_compare(x,y) == 0);
|
||||
|
@ -665,7 +589,7 @@ static int mmsbox_service_dispatch(MmsEnvelope *e)
|
|||
}
|
||||
|
||||
me = mms_tomime(msg, 0);
|
||||
keyword = get_keyword(me);
|
||||
keyword = get_keyword_from_mime(me);
|
||||
|
||||
xto = gwlist_get(e->to, 0);
|
||||
ms = get_service(keyword, e->fromproxy, xto ? xto->rcpt : NULL);
|
||||
|
|
Loading…
Reference in New Issue