* mu extract: display size of mime parts

(updates in mu-cmd-extract.c, mu-msg-part.[ch])
This commit is contained in:
djcb
2011-11-18 12:20:42 +02:00
parent ff4ca20a6f
commit dc7b713c48
3 changed files with 57 additions and 27 deletions

View File

@ -319,6 +319,14 @@ each_part_show (MuMsg *msg, MuMsgPart *part, gboolean color)
color_maybe (MU_COLOR_MAGENTA); color_maybe (MU_COLOR_MAGENTA);
mu_util_print_encoded ( mu_util_print_encoded (
"[%s]", part->disposition ? part->disposition : "<none>"); "[%s]", part->disposition ? part->disposition : "<none>");
/* size */
if (part->size > 0) {
color_maybe (MU_COLOR_CYAN);
g_print (" (%s)", mu_str_size_s (part->size));
}
color_maybe (MU_COLOR_DEFAULT); color_maybe (MU_COLOR_DEFAULT);
fputs ("\n", stdout); fputs ("\n", stdout);
} }

View File

@ -70,6 +70,27 @@ struct _PartData {
typedef struct _PartData PartData; typedef struct _PartData PartData;
static ssize_t
get_part_size (GMimePart *part)
{
GMimeDataWrapper *wrapper;
GMimeStream *stream;
wrapper = g_mime_part_get_content_object (part);
if (!wrapper)
return -1;
stream = g_mime_data_wrapper_get_stream (wrapper);
if (!stream)
return -1;
/* NOTE: it seems we shouldn't unref stream/wrapper */
return g_mime_stream_length (stream);
}
static void static void
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartData *pdata) part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartData *pdata)
{ {
@ -90,6 +111,7 @@ part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartData *pdata)
if (GMIME_IS_PART(part)) { if (GMIME_IS_PART(part)) {
pi.disposition = (char*)g_mime_object_get_disposition (part); pi.disposition = (char*)g_mime_object_get_disposition (part);
pi.file_name = (char*)g_mime_part_get_filename (GMIME_PART(part)); pi.file_name = (char*)g_mime_part_get_filename (GMIME_PART(part));
pi.size = get_part_size (GMIME_PART(part));
} }
pdata->_func(pdata->_msg, &pi, pdata->_user_data); pdata->_func(pdata->_msg, &pi, pdata->_user_data);

View File

@ -33,9 +33,9 @@ struct _MuMsgPart {
/* cid */ /* cid */
char *content_id; char *content_id;
/* content-type: type/subtype, ie. text/plain */ /* content-type: type/subtype, ie. text/plain */
char *type; char *type;
char *subtype; char *subtype;
/* full content-type, e.g. image/jpeg */ /* full content-type, e.g. image/jpeg */
/* char *content_type; */ /* char *content_type; */
@ -45,12 +45,12 @@ struct _MuMsgPart {
/* usually, "attachment" or "inline" */ /* usually, "attachment" or "inline" */
char *disposition; char *disposition;
/* size of the part; or 0 if unknown */ /* size of the part; or <= 0 if unknown */
size_t *size; size_t size;
gpointer data; /* opaque data */ gpointer data; /* opaque data */
/* if TRUE, mu_msg_part_destroy will free the member vars /* if TRUE, mu_msg_part_destroy will free the member vars
* as well*/ * as well*/
gboolean own_members; gboolean own_members;
@ -59,9 +59,9 @@ typedef struct _MuMsgPart MuMsgPart;
/** /**
* macro to get the file name for this mime-part * macro to get the file name for this mime-part
* *
* @param pi a MuMsgPart instance * @param pi a MuMsgPart instance
* *
* @return the file name * @return the file name
*/ */
#define mu_msg_part_file_name(pi) ((pi)->file_name) #define mu_msg_part_file_name(pi) ((pi)->file_name)
@ -69,9 +69,9 @@ typedef struct _MuMsgPart MuMsgPart;
/** /**
* macro to get the content-id (cid) for this mime-part * macro to get the content-id (cid) for this mime-part
* *
* @param pi a MuMsgPart instance * @param pi a MuMsgPart instance
* *
* @return the file name * @return the file name
*/ */
#define mu_msg_part_content_id(pi) ((pi)->content_id) #define mu_msg_part_content_id(pi) ((pi)->content_id)
@ -79,25 +79,25 @@ typedef struct _MuMsgPart MuMsgPart;
/** /**
* does this msg part look like an attachment? * does this msg part look like an attachment?
* *
* @param part a message part * @param part a message part
* @param include_inline consider 'inline' parts also as attachments * @param include_inline consider 'inline' parts also as attachments
* *
* @return TRUE if it looks like an attachment, FALSE otherwise * @return TRUE if it looks like an attachment, FALSE otherwise
*/ */
gboolean mu_msg_part_looks_like_attachment (MuMsgPart *part, gboolean mu_msg_part_looks_like_attachment (MuMsgPart *part,
gboolean include_inline); gboolean include_inline);
/** /**
* save a specific attachment to some targetdir * save a specific attachment to some targetdir
* *
* @param msg a valid MuMsg instance * @param msg a valid MuMsg instance
* @gchar filepath the filepath to save * @gchar filepath the filepath to save
* @param partidx index of the attachment you want to save * @param partidx index of the attachment you want to save
* @param overwrite overwrite existing files? * @param overwrite overwrite existing files?
* @param don't raise error when the file already exists * @param don't raise error when the file already exists
* @param err receives error information (when function returns NULL) * @param err receives error information (when function returns NULL)
* *
* @return full path to the message part saved or NULL in case or error; free with g_free * @return full path to the message part saved or NULL in case or error; free with g_free
*/ */
gboolean mu_msg_part_save (MuMsg *msg, const char *filepath, guint partidx, gboolean mu_msg_part_save (MuMsg *msg, const char *filepath, guint partidx,
@ -108,25 +108,25 @@ gboolean mu_msg_part_save (MuMsg *msg, const char *filepath, guint partidx,
* get a filename for the saving the message part; try the filename * get a filename for the saving the message part; try the filename
* specified for the message part if any, otherwise determine a unique * specified for the message part if any, otherwise determine a unique
* name based on the partidx and the message path * name based on the partidx and the message path
* *
* @param msg a msg * @param msg a msg
* @param targetdir where to store the part * @param targetdir where to store the part
* @param partidx the part for which to determine a filename * @param partidx the part for which to determine a filename
* *
* @return a filepath (g_free when done with it) or NULL in case of error * @return a filepath (g_free when done with it) or NULL in case of error
*/ */
gchar* mu_msg_part_filepath (MuMsg *msg, const char* targetdir, gchar* mu_msg_part_filepath (MuMsg *msg, const char* targetdir,
guint partidx) G_GNUC_WARN_UNUSED_RESULT; guint partidx) G_GNUC_WARN_UNUSED_RESULT;
/** /**
* get a full path name for saving the message part in the cache * get a full path name for saving the message part in the cache
* directory for this message; if needed, create the directory (but * directory for this message; if needed, create the directory (but
* not the file) * not the file)
* *
* @param msg a msg * @param msg a msg
* @param partidx the part for which to determine a filename * @param partidx the part for which to determine a filename
* *
* @return a filepath (g_free when done with it) or NULL in case of error * @return a filepath (g_free when done with it) or NULL in case of error
*/ */
gchar* mu_msg_part_filepath_cache (MuMsg *msg, guint partid) gchar* mu_msg_part_filepath_cache (MuMsg *msg, guint partid)
@ -135,20 +135,20 @@ gchar* mu_msg_part_filepath_cache (MuMsg *msg, guint partid)
/** /**
* get the part index for the message part with a certain content-id * get the part index for the message part with a certain content-id
* *
* @param msg a message * @param msg a message
* @param content_id a content-id to search * @param content_id a content-id to search
* *
* @return the part index number of the found part, or -1 if it was not found * @return the part index number of the found part, or -1 if it was not found
*/ */
int mu_msg_part_find_cid (MuMsg *msg, const char* content_id); int mu_msg_part_find_cid (MuMsg *msg, const char* content_id);
/** /**
* retrieve a list of indices for mime-parts with filenames matching a regex * retrieve a list of indices for mime-parts with filenames matching a regex
* *
* @param msg a message * @param msg a message
* @param a regular expression to match the filename with * @param a regular expression to match the filename with
* *
* @return a list with indices for the files matching the pattern; the * @return a list with indices for the files matching the pattern; the
* indices are the GPOINTER_TO_UINT(lst->data) of the list. They must * indices are the GPOINTER_TO_UINT(lst->data) of the list. They must
* be freed with g_slist_free * be freed with g_slist_free
@ -158,13 +158,13 @@ GSList* mu_msg_part_find_files (MuMsg *msg, const GRegex *pattern);
typedef void (*MuMsgPartForeachFunc) (MuMsg*, MuMsgPart*, gpointer); typedef void (*MuMsgPartForeachFunc) (MuMsg*, MuMsgPart*, gpointer);
/** /**
* call a function for each of the mime part in a message * call a function for each of the mime part in a message
* *
* @param msg a valid MuMsg* instance * @param msg a valid MuMsg* instance
* @param func a callback function to call for each contact; when * @param func a callback function to call for each contact; when
* the callback does not return TRUE, it won't be called again * 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 * @param user_data a user-provide pointer that will be passed to the callback
* *
*/ */
void mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func, void mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func,
gpointer user_data); gpointer user_data);