mirror of https://github.com/djcb/mu.git
* next step in attachment handling infra; still WIP
This commit is contained in:
parent
37b0ea3bc3
commit
3cdb1f15ed
|
@ -24,6 +24,18 @@
|
|||
#include "mu-cmd.h"
|
||||
|
||||
|
||||
static void
|
||||
each_part (MuMsgPartInfo* part, gpointer user_data)
|
||||
{
|
||||
g_print ("%u %s %s/%s [%s]\n",
|
||||
part->index,
|
||||
part->file_name ? part->file_name : "<none>",
|
||||
part->type ? part->type : "",
|
||||
part->subtype ? part->subtype : "",
|
||||
part->disposition ? part->disposition : "<none>");
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
show_parts (const char* path)
|
||||
{
|
||||
|
@ -33,7 +45,9 @@ show_parts (const char* path)
|
|||
if (!msg)
|
||||
return FALSE;
|
||||
|
||||
mu_msg_gmime_mime_part_foreach (msg, NULL, NULL);
|
||||
mu_msg_gmime_msg_part_infos_foreach (msg, each_part, NULL);
|
||||
|
||||
mu_msg_gmime_destroy (msg);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
|
|
@ -772,46 +772,6 @@ mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines)
|
|||
|
||||
|
||||
|
||||
struct _PartData {
|
||||
MuMsgMimePartForeachFunc _func;
|
||||
gpointer _user_data;
|
||||
};
|
||||
typedef struct _PartData PartData;
|
||||
|
||||
|
||||
static void
|
||||
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartData *data)
|
||||
{
|
||||
GMimeContentType *ct;
|
||||
|
||||
ct = g_mime_object_get_content_type (part);
|
||||
|
||||
if (!GMIME_IS_CONTENT_TYPE(ct)) {
|
||||
g_warning ("not a content type!");
|
||||
return;
|
||||
}
|
||||
|
||||
g_print ("%s\n", g_mime_content_type_to_string (ct));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg, MuMsgMimePartForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
PartData pdata;
|
||||
|
||||
g_return_if_fail (msg);
|
||||
g_return_if_fail (GMIME_IS_OBJECT(msg->_mime_msg));
|
||||
|
||||
pdata._func = func;
|
||||
pdata._user_data = user_data;
|
||||
|
||||
g_mime_message_foreach (msg->_mime_msg,
|
||||
(GMimeObjectForeachFunc)part_foreach_cb,
|
||||
&pdata);
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
|
@ -986,7 +946,7 @@ each_contact (MuMsgContact *contact, GSList **lst)
|
|||
|
||||
|
||||
GSList *
|
||||
mu_msg_gmime_contacts_list (MuMsgGMime *msg)
|
||||
mu_msg_gmime_get_contacts (MuMsgGMime *msg)
|
||||
{
|
||||
GSList *contacts;
|
||||
|
||||
|
@ -1023,3 +983,66 @@ mu_msg_gmime_uninit (void)
|
|||
g_debug ("%s", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct _PartData {
|
||||
unsigned _idx;
|
||||
MuMsgPartInfoForeachFunc _func;
|
||||
gpointer _user_data;
|
||||
};
|
||||
typedef struct _PartData PartData;
|
||||
|
||||
|
||||
static void
|
||||
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartData *pdata)
|
||||
{
|
||||
GMimeContentType *ct;
|
||||
GMimeContentDisposition *cd;
|
||||
MuMsgPartInfo pi;
|
||||
|
||||
ct = g_mime_object_get_content_type (part);
|
||||
|
||||
/* ignore non-MIME */
|
||||
if (!GMIME_IS_CONTENT_TYPE(ct)) {
|
||||
g_debug ("not a content type!");
|
||||
return;
|
||||
}
|
||||
|
||||
memset (&pi, 0, sizeof pi);
|
||||
pi.index = pdata->_idx++;
|
||||
pi.content_id = (char*)g_mime_object_get_content_id (part);
|
||||
pi.type = (char*)g_mime_content_type_get_media_type (ct);
|
||||
pi.subtype = (char*)g_mime_content_type_get_media_subtype (ct);
|
||||
pi.disposition = (char*)g_mime_object_get_disposition (part);
|
||||
|
||||
cd = g_mime_object_get_content_disposition (part);
|
||||
if (GMIME_IS_CONTENT_DISPOSITION(cd))
|
||||
pi.file_name = (char*)g_mime_content_disposition_get_parameter
|
||||
(cd , "filename");
|
||||
|
||||
pdata->_func(&pi, pdata->_user_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
mu_msg_gmime_msg_part_infos_foreach (MuMsgGMime *msg,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
PartData pdata;
|
||||
|
||||
g_return_if_fail (msg);
|
||||
g_return_if_fail (GMIME_IS_OBJECT(msg->_mime_msg));
|
||||
|
||||
pdata._idx = 0;
|
||||
pdata._func = func;
|
||||
pdata._user_data = user_data;
|
||||
|
||||
g_mime_message_foreach (msg->_mime_msg,
|
||||
(GMimeObjectForeachFunc)part_foreach_cb,
|
||||
&pdata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "mu-msg.h"
|
||||
#include "mu-msg-contact.h"
|
||||
#include "mu-msg-part-info.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -323,10 +324,10 @@ time_t mu_msg_gmime_get_timestamp (MuMsgGMime *msg);
|
|||
*
|
||||
* @param msg a valid MuMsgGMime* instance
|
||||
*
|
||||
* @return a list of contacts for this message; use mu_msg_contact_list_free
|
||||
* to free it when done
|
||||
* @return a list of contacts for this message; use
|
||||
* mu_msg_contacts_free to free it when done
|
||||
*/
|
||||
GSList * mu_msg_gmime_contacts_list (MuMsgGMime *msg);
|
||||
GSList * mu_msg_gmime_get_contacts (MuMsgGMime *msg);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -341,6 +342,32 @@ GSList * mu_msg_gmime_contacts_list (MuMsgGMime *msg);
|
|||
void mu_msg_gmime_contacts_foreach (MuMsgGMime *msg,
|
||||
MuMsgContactForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/* /\** */
|
||||
/* * get a list of message part info objects (MuMsgPartInfo) for this */
|
||||
/* * message; you can use GSList functions or */
|
||||
/* * mu_msg_part_info_list_foreach to read the items. */
|
||||
/* * */
|
||||
/* * @param msg a valid MuMsgGMime* instance */
|
||||
/* * */
|
||||
/* * @return a list of contacts for this message; use */
|
||||
/* * mu_msg_part_infos_free to free it when done */
|
||||
/* *\/ */
|
||||
/* GSList *mu_msg_gmime_get_part_infos (MuMsgGMime *msg); */
|
||||
|
||||
|
||||
/**
|
||||
* call a function for each of the contacts in a message
|
||||
*
|
||||
* @param msg a valid MuMsgGMime* instance
|
||||
* @param func a callback function to call for each contact; when
|
||||
* the callback does not return TRUE, it won't be called again
|
||||
* @param user_data a user-provide pointer that will be passed to the callback
|
||||
*
|
||||
*/
|
||||
void mu_msg_gmime_msg_part_infos_foreach (MuMsgGMime *msg,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data);
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_MSG_GIME_H__*/
|
||||
|
|
|
@ -21,10 +21,8 @@
|
|||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "mu-msg-part-info.h"
|
||||
|
||||
|
||||
MuMsgPartInfo*
|
||||
mu_msg_part_info_new (void)
|
||||
{
|
||||
|
@ -33,16 +31,16 @@ mu_msg_part_info_new (void)
|
|||
|
||||
|
||||
void
|
||||
mu_msg_part_info_destroy (MuMsgPartInfo *pi, gboolean destroy_members)
|
||||
mu_msg_part_info_destroy (MuMsgPartInfo *pi)
|
||||
{
|
||||
if (!pi)
|
||||
return;
|
||||
|
||||
if (destroy_members) {
|
||||
if (pi->own_members) {
|
||||
g_free (pi->content_id);
|
||||
g_free (pi->type);
|
||||
g_free (pi->subtype);
|
||||
g_free (pi->content_type);
|
||||
/* g_free (pi->content_type); */
|
||||
g_free (pi->file_name);
|
||||
g_free (pi->disposition);
|
||||
}
|
||||
|
@ -53,20 +51,18 @@ mu_msg_part_info_destroy (MuMsgPartInfo *pi, gboolean destroy_members)
|
|||
|
||||
|
||||
void
|
||||
mu_msg_part_info_list_foreach (GSList *lst,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data)
|
||||
mu_msg_part_infos_foreach (GSList *lst,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
while (lst && func((MuMsgPartInfo*)lst->data, user_data))
|
||||
lst = g_slist_next(lst);
|
||||
for (; lst ; lst = g_slist_next (lst))
|
||||
func((MuMsgPartInfo*)lst->data, user_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void /* FIXME: destroy_members */
|
||||
mu_msg_part_info_list_free (GSList *lst, gboolean destroy_members)
|
||||
void
|
||||
mu_msg_part_infos_free (GSList *lst)
|
||||
{
|
||||
|
||||
g_slist_foreach (lst, (GFunc)mu_msg_part_info_destroy, NULL);
|
||||
g_slist_free (lst);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
struct _MuMsgPartInfo {
|
||||
|
||||
/* index of this message */
|
||||
guint index;
|
||||
unsigned index;
|
||||
|
||||
/* cid */
|
||||
char *content_id;
|
||||
|
@ -34,7 +34,7 @@ struct _MuMsgPartInfo {
|
|||
char *type;
|
||||
char *subtype;
|
||||
/* full content-type, e.g. image/jpeg */
|
||||
char *content_type;
|
||||
/* char *content_type; */
|
||||
|
||||
/* the file name (if any) */
|
||||
char *file_name;
|
||||
|
@ -46,6 +46,10 @@ struct _MuMsgPartInfo {
|
|||
|
||||
/* size of the part; or 0 if unknown */
|
||||
size_t *size;
|
||||
|
||||
/* if TRUE, mu_msg_part_info_destroy will free the member vars
|
||||
* as well*/
|
||||
gboolean own_members;
|
||||
};
|
||||
typedef struct _MuMsgPartInfo MuMsgPartInfo;
|
||||
|
||||
|
@ -64,12 +68,8 @@ MuMsgPartInfo *mu_msg_part_info_new (void);
|
|||
* destroy a MuMsgPartInfo object
|
||||
*
|
||||
* @param ct a MuMsgPartInfo object, or NULL
|
||||
* @param destroy_members TRUE if members should be destroyed as well,
|
||||
* FALSE otherwise
|
||||
*/
|
||||
void mu_msg_part_info_destroy (MuMsgPartInfo *pinfo,
|
||||
gboolean destroy_members);
|
||||
|
||||
void mu_msg_part_info_destroy (MuMsgPartInfo *pinfo);
|
||||
|
||||
/**
|
||||
* macro to get the file name for this mime-part
|
||||
|
@ -96,10 +96,9 @@ void mu_msg_part_info_destroy (MuMsgPartInfo *pinfo,
|
|||
* @param a msg part info object
|
||||
* @param user_data a user provided data pointer
|
||||
*
|
||||
* @return TRUE if we should continue the foreach, FALSE otherwise
|
||||
*/
|
||||
typedef gboolean (*MuMsgPartInfoForeachFunc) (MuMsgPartInfo* part,
|
||||
gpointer user_data);
|
||||
typedef void (*MuMsgPartInfoForeachFunc) (MuMsgPartInfo* part,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
* call a function for each MuMsgPartInfo (MIME-part) in the list
|
||||
|
@ -108,15 +107,15 @@ typedef gboolean (*MuMsgPartInfoForeachFunc) (MuMsgPartInfo* part,
|
|||
* @param func a callback function
|
||||
* @param user_data user pointer, passed to the callback
|
||||
*/
|
||||
void mu_msg_part_info_list_foreach (GSList *lst,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data);
|
||||
void mu_msg_part_infos_foreach (GSList *lst,
|
||||
MuMsgPartInfoForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
* free a list of MuMsgPartInfo objects
|
||||
*
|
||||
* @param lst list of MuMsgPartInfo object
|
||||
*/
|
||||
void mu_msg_part_info_list_free (GSList *lst, gboolean destroy_members);
|
||||
void mu_msg_part_infos_free (GSList *lst);
|
||||
|
||||
#endif /*__MU_MSG_PART_INFO_H__*/
|
||||
|
|
|
@ -91,7 +91,7 @@ test_mu_msg_gmime_01 (void)
|
|||
==, 1217530645);
|
||||
{
|
||||
GSList *lst, *cur;
|
||||
lst = mu_msg_gmime_contacts_list (msg);
|
||||
lst = mu_msg_gmime_get_contacts (msg);
|
||||
g_assert_cmpuint (g_slist_length(lst),==, 2);
|
||||
cur = lst;
|
||||
|
||||
|
@ -108,7 +108,7 @@ test_mu_msg_gmime_01 (void)
|
|||
==, "gcc-help@gcc.gnu.org");
|
||||
|
||||
|
||||
mu_msg_contact_list_free (lst);
|
||||
mu_msg_contacts_free (lst);
|
||||
}
|
||||
|
||||
mu_msg_gmime_destroy (msg);
|
||||
|
@ -148,7 +148,7 @@ test_mu_msg_gmime_02 (void)
|
|||
|
||||
{
|
||||
GSList *lst, *cur;
|
||||
lst = mu_msg_gmime_contacts_list (msg);
|
||||
lst = mu_msg_gmime_get_contacts (msg);
|
||||
g_assert_cmpuint (g_slist_length(lst),==, 2);
|
||||
cur = lst;
|
||||
|
||||
|
@ -165,7 +165,7 @@ test_mu_msg_gmime_02 (void)
|
|||
==, "help-gnu-emacs@gnu.org");
|
||||
|
||||
|
||||
mu_msg_contact_list_free (lst);
|
||||
mu_msg_contacts_free (lst);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue