LUA_FUNCTION_DEF (message, get_reply_to);
LUA_FUNCTION_DEF (message, set_reply_to);
LUA_FUNCTION_DEF (message, get_header);
+LUA_FUNCTION_DEF (message, get_header_strong);
LUA_FUNCTION_DEF (message, set_header);
static const struct luaL_reg msglib_m[] = {
LUA_INTERFACE_DEF (message, get_reply_to),
LUA_INTERFACE_DEF (message, set_reply_to),
LUA_INTERFACE_DEF (message, get_header),
+ LUA_INTERFACE_DEF (message, get_header_strong),
LUA_INTERFACE_DEF (message, set_header),
{"__tostring", lua_class_tostring},
{NULL, NULL}
LUA_GMIME_BRIDGE_SET (message, set_reply_to, Message)
static gint
-lua_message_get_header (lua_State * L)
+lua_message_get_header_common (lua_State * L, gboolean strong)
{
const gchar *headern;
GMimeMessage *obj = lua_check_message (L);
if (obj != NULL) {
headern = luaL_checkstring (L, 2);
if (headern) {
- res = message_get_header (NULL, obj, headern);
+ res = message_get_header (NULL, obj, headern, strong);
if (res) {
cur = res;
lua_newtable (L);
return 1;
}
+static gint
+lua_message_get_header (lua_State * L)
+{
+ return lua_message_get_header_common (L, FALSE);
+}
+
+static gint
+lua_message_get_header_strong (lua_State * L)
+{
+ return lua_message_get_header_common (L, TRUE);
+}
static gint
lua_message_set_header (lua_State * L)
#endif
/* Parse received headers */
- first = message_get_header (task->task_pool, message, "Received");
+ first = message_get_header (task->task_pool, message, "Received", FALSE);
cur = first;
while (cur) {
recv = memory_pool_alloc0 (task->task_pool, sizeof (struct received_header));
#ifndef GMIME24
static void
-header_iterate (memory_pool_t * pool, struct raw_header *h, GList ** ret, const gchar *field)
+header_iterate (memory_pool_t * pool, struct raw_header *h, GList ** ret, const gchar *field, gboolean strong)
{
while (h) {
- if (h->value && !g_strncasecmp (field, h->name, strlen (field))) {
- if (pool != NULL) {
- *ret = g_list_prepend (*ret, memory_pool_strdup (pool, h->value));
+ if (G_LIKELY (!strong)) {
+ if (h->value && !g_strncasecmp (field, h->name, strlen (field))) {
+ if (pool != NULL) {
+ *ret = g_list_prepend (*ret, memory_pool_strdup (pool, h->value));
+ }
+ else {
+ *ret = g_list_prepend (*ret, g_strdup (h->value));
+ }
}
- else {
- *ret = g_list_prepend (*ret, g_strdup (h->value));
+ }
+ else {
+ if (h->value && !strncmp (field, h->name, strlen (field))) {
+ if (pool != NULL) {
+ *ret = g_list_prepend (*ret, memory_pool_strdup (pool, h->value));
+ }
+ else {
+ *ret = g_list_prepend (*ret, g_strdup (h->value));
+ }
}
}
h = h->next;
}
#else
static void
-header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const gchar *field)
+header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const gchar *field, gboolean strong)
{
GMimeHeaderIter *iter;
const gchar *name;
if (g_mime_header_list_get_iter (ls, iter) && g_mime_header_iter_first (iter)) {
while (g_mime_header_iter_is_valid (iter)) {
name = g_mime_header_iter_get_name (iter);
- if (!g_strncasecmp (field, name, strlen (name))) {
- if (pool != NULL) {
- *ret = g_list_prepend (*ret, memory_pool_strdup (pool, g_mime_header_iter_get_value (iter)));
+ if (G_LIKELY (!strong)) {
+ if (!g_strncasecmp (field, name, strlen (name))) {
+ if (pool != NULL) {
+ *ret = g_list_prepend (*ret, memory_pool_strdup (pool, g_mime_header_iter_get_value (iter)));
+ }
+ else {
+ *ret = g_list_prepend (*ret, g_strdup (g_mime_header_iter_get_value (iter)));
+ }
}
- else {
- *ret = g_list_prepend (*ret, g_strdup (g_mime_header_iter_get_value (iter)));
+ }
+ else {
+ if (!strncmp (field, name, strlen (name))) {
+ if (pool != NULL) {
+ *ret = g_list_prepend (*ret, memory_pool_strdup (pool, g_mime_header_iter_get_value (iter)));
+ }
+ else {
+ *ret = g_list_prepend (*ret, g_strdup (g_mime_header_iter_get_value (iter)));
+ }
}
}
if (!g_mime_header_iter_next (iter)) {
memory_pool_t *pool;
const gchar *field;
gboolean try_search;
+ gboolean strong;
gint rec;
};
GMimeHeaderList *ls;
ls = g_mime_object_get_header_list (GMIME_OBJECT (part));
- header_iterate (data->pool, ls, &l, data->field);
+ header_iterate (data->pool, ls, &l, data->field, data->strong);
#else
h = part->headers->headers;
- header_iterate (data->pool, h, &l, data->field);
+ header_iterate (data->pool, h, &l, data->field, data->strong);
#endif
if (l == NULL) {
/* Header not found, abandon search results */
}
static GList *
-local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field)
+local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong)
{
GList *gret = NULL;
GMimeObject *part;
};
cb.pool = pool;
cb.field = field;
+ cb.strong = strong;
#ifndef GMIME24
struct raw_header *h;
msg_debug ("iterate over headers to find header %s", field);
h = GMIME_OBJECT (message)->headers->headers;
- header_iterate (pool, h, &gret, field);
+ header_iterate (pool, h, &gret, field, strong);
if (gret == NULL) {
/* Try to iterate with mime part headers */
part = g_mime_message_get_mime_part (message);
if (part) {
h = part->headers->headers;
- header_iterate (pool, h, &gret, field);
+ header_iterate (pool, h, &gret, field, strong);
if (gret == NULL && GMIME_IS_MULTIPART (part)) {
msg_debug ("iterate over headers of each multipart's subparts %s", field);
g_mime_multipart_foreach (GMIME_MULTIPART (part), multipart_iterate, &cb);
GMimeHeaderList *ls;
ls = g_mime_object_get_header_list (GMIME_OBJECT (message));
- header_iterate (pool, ls, &gret, field);
+ header_iterate (pool, ls, &gret, field, strong);
if (gret == NULL) {
/* Try to iterate with mime part headers */
part = g_mime_message_get_mime_part (message);
if (part) {
ls = g_mime_object_get_header_list (GMIME_OBJECT (part));
- header_iterate (pool, ls, &gret, field);
+ header_iterate (pool, ls, &gret, field, strong);
if (gret == NULL && GMIME_IS_MULTIPART (part)) {
g_mime_multipart_foreach (GMIME_MULTIPART (part), multipart_iterate, &cb);
if (cb.ret != NULL) {
/* different declarations for different types of set and get functions */
typedef const gchar *(*GetFunc) (GMimeMessage * message);
typedef InternetAddressList *(*GetRcptFunc) (GMimeMessage * message, const gchar *type);
- typedef GList *(*GetListFunc) (memory_pool_t * pool, GMimeMessage * message, const gchar *type);
+ typedef GList *(*GetListFunc) (memory_pool_t * pool, GMimeMessage * message, const gchar *type, gboolean strong);
typedef void (*SetFunc) (GMimeMessage * message, const gchar *value);
typedef void (*SetListFunc) (GMimeMessage * message, const gchar *field, const gchar *value);
* You should free the GList list by yourself.
**/
GList *
-message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field)
+message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong)
{
gint i;
gchar *ret = NULL, *ia_string;
#endif
break;
case FUNC_LIST:
- gret = (*(fieldfunc[i].getlistfunc)) (pool, message, field);
+ gret = (*(fieldfunc[i].getlistfunc)) (pool, message, field, strong);
break;
}
break;