* WIP: added MuMsgPartInfo (WIP)

This commit is contained in:
Dirk-Jan C. Binnema 2010-08-21 20:44:13 +03:00
parent fc40900037
commit 596317b8dc
4 changed files with 215 additions and 10 deletions

View File

@ -46,13 +46,13 @@ mu_LDADD= \
libmu.la
libmu_la_SOURCES= \
mu-cmd.c \
mu-cmd.h \
mu-cmd-extract.c \
mu-cmd-find.c \
mu-cmd-index.c \
mu-cmd-view.c \
mu-cmd-mkdir.c \
mu-cmd-extract.c \
mu-cmd-view.c \
mu-cmd.c \
mu-cmd.h \
mu-config.c \
mu-config.h \
mu-index.c \
@ -72,6 +72,8 @@ libmu_la_SOURCES= \
mu-msg-iter-xapian-priv.hh \
mu-msg-iter-xapian.cc \
mu-msg-iter-xapian.h \
mu-msg-part-info.c \
mu-msg-part-info.h \
mu-msg-str.c \
mu-msg-str.h \
mu-msg.h \

View File

@ -772,16 +772,20 @@ mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines)
struct _PartForeachData {};
typedef struct _PartForeachData PartForeachData;
struct _PartData {
MuMsgMimePartForeachFunc _func;
gpointer _user_data;
};
typedef struct _PartData PartData;
static void
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartForeachData *data)
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;
@ -794,19 +798,24 @@ part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartForeachData *data)
void
mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg, MuMsgMimePartForeachFunc func,
gpointer user_data)
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,
NULL);
&pdata);
}
gboolean
mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned num,
mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned idx,
const char *targetdir)
{
return TRUE; /* FIXME */

72
src/mu-msg-part-info.c Normal file
View File

@ -0,0 +1,72 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
#include <glib.h>
#include "mu-msg-part-info.h"
MuMsgPartInfo*
mu_msg_part_info_new (void)
{
return g_slice_new0 (MuMsgPartInfo);
}
void
mu_msg_part_info_destroy (MuMsgPartInfo *pi, gboolean destroy_members)
{
if (!pi)
return;
if (destroy_members) {
g_free (pi->content_id);
g_free (pi->type);
g_free (pi->subtype);
g_free (pi->content_type);
g_free (pi->file_name);
g_free (pi->disposition);
}
g_slice_free (MuMsgPartInfo, pi);
}
void
mu_msg_part_info_list_foreach (GSList *lst,
MuMsgPartInfoForeachFunc func,
gpointer user_data)
{
while (lst && func((MuMsgPartInfo*)lst->data, user_data))
lst = g_slist_next(lst);
}
void /* FIXME: destroy_members */
mu_msg_part_info_list_free (GSList *lst, gboolean destroy_members)
{
g_slist_foreach (lst, (GFunc)mu_msg_part_info_destroy, NULL);
g_slist_free (lst);
}

122
src/mu-msg-part-info.h Normal file
View File

@ -0,0 +1,122 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#ifndef __MU_MSG_PART_INFO_H__
#define __MU_MSG_PART_INFO_H__
#include <glib.h>
struct _MuMsgPartInfo {
/* index of this message */
guint index;
/* cid */
char *content_id;
/* content-type: type/subtype, ie. text/plain */
char *type;
char *subtype;
/* full content-type, e.g. image/jpeg */
char *content_type;
/* the file name (if any) */
char *file_name;
/* usually, "attachment" or "inline"; use
* mu_msg_part_info_is_(attachment|inline)
* to test */
char *disposition;
/* size of the part; or 0 if unknown */
size_t *size;
};
typedef struct _MuMsgPartInfo MuMsgPartInfo;
/**
* create a new MuMsgPartInfo instance; this just allocates the
* memory, you'll have to fill it yourself
*
*
* @return a new MuMsgPartInfo instance; use mu_msg_part_info_destroy
* when finished.
*/
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);
/**
* macro to get the file name for this mime-part
*
* @param pi a MuMsgPartInfo instance
*
* @return the file name
*/
#define mu_msg_part_info_file_name(pi) ((pi)->file_name)
/**
* macro to get the file name for this mime-part
*
* @param pi a MuMsgPartInfo instance
*
* @return the file name
*/
#define mu_msg_part_content_type(pi) ((pi)->content_type)
/**
* callback function
*
* @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);
/**
* call a function for each MuMsgPartInfo (MIME-part) in the list
*
* @param lst a list of MuMsgPartInfo objects
* @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);
/**
* free a list of MuMsgPartInfo objects
*
* @param lst list of MuMsgPartInfo object
*/
void mu_msg_part_info_list_free (GSList *lst, gboolean destroy_members);
#endif /*__MU_MSG_PART_INFO_H__*/