New function, to copy a message from one folder to another. The default
2000-06-30 Jeffrey Stedfast <fejj@helixcode.com> * camel-folder.c (camel_folder_copy_message_to): New function, to copy a message from one folder to another. The default implementation just uses append_message, but providers can implement more efficient versions for use when both folders are on the same store. * broken-date-parser.[c,h]: Utilities for parsing broken date strings. * providers/imap/camel-imap-folder.c (imap_move_message_to): (imap_copy_message_to): Implemented. * camel-mime-utils.c (header_decode_date): Wrote some code to try and un-mangle broken date formats and then parse that new string instead. svn path=/trunk/; revision=3841
This commit is contained in:
committed by
Jeffrey Stedfast
parent
c07840479d
commit
f278d3041b
@ -1,10 +1,16 @@
|
||||
2000-06-30 Jeffrey Stedfast <fejj@helixcode.com>
|
||||
|
||||
* camel-folder.c (camel_folder_copy_message_to): New function, to
|
||||
copy a message from one folder to another. The default
|
||||
implementation just uses append_message, but providers can
|
||||
implement more efficient versions for use when both folders are on
|
||||
the same store.
|
||||
|
||||
* broken-date-parser.[c,h]: Utilities for parsing broken
|
||||
date strings.
|
||||
|
||||
* providers/imap/camel-imap-folder.c (imap_move_message_to):
|
||||
Implemented.
|
||||
(imap_copy_message_to): Implemented.
|
||||
|
||||
* camel-mime-utils.c (header_decode_date): Wrote some code to try
|
||||
and un-mangle broken date formats and then parse that new string
|
||||
|
||||
@ -122,6 +122,11 @@ static const CamelMessageInfo *summary_get_by_uid (CamelFolder *folder,
|
||||
static GList *search_by_expression (CamelFolder *folder, const char *exp,
|
||||
CamelException *ex);
|
||||
|
||||
static void copy_message_to (CamelFolder *source,
|
||||
const char *uid,
|
||||
CamelFolder *dest,
|
||||
CamelException *ex);
|
||||
|
||||
static void move_message_to (CamelFolder *source,
|
||||
const char *uid,
|
||||
CamelFolder *dest,
|
||||
@ -164,6 +169,7 @@ camel_folder_class_init (CamelFolderClass *camel_folder_class)
|
||||
camel_folder_class->free_summary = free_summary;
|
||||
camel_folder_class->search_by_expression = search_by_expression;
|
||||
camel_folder_class->summary_get_by_uid = summary_get_by_uid;
|
||||
camel_folder_class->copy_message_to = copy_message_to;
|
||||
camel_folder_class->move_message_to = move_message_to;
|
||||
|
||||
/* virtual method overload */
|
||||
@ -1021,6 +1027,50 @@ camel_folder_search_by_expression (CamelFolder *folder, const char *expression,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
copy_message_to (CamelFolder *source, const char *uid, CamelFolder *dest,
|
||||
CamelException *ex)
|
||||
{
|
||||
CamelMimeMessage *msg;
|
||||
|
||||
/* Default implementation. */
|
||||
|
||||
msg = camel_folder_get_message_by_uid (source, uid, ex);
|
||||
if (!msg)
|
||||
return;
|
||||
camel_folder_append_message (dest, msg, ex);
|
||||
gtk_object_unref (GTK_OBJECT (msg));
|
||||
if (camel_exception_is_set (ex))
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* camel_folder_copy_message_to:
|
||||
* @source: source folder
|
||||
* @uid: UID of message in @source
|
||||
* @dest: destination folder
|
||||
* @ex: a CamelException
|
||||
*
|
||||
* This copies a message from one folder to another. If the @source and
|
||||
* @dest folders have the same parent_store, this may be more efficient
|
||||
* than a camel_folder_append_message().
|
||||
**/
|
||||
void
|
||||
camel_folder_copy_message_to (CamelFolder *source, const char *uid,
|
||||
CamelFolder *dest, CamelException *ex)
|
||||
{
|
||||
g_return_if_fail (CAMEL_IS_FOLDER (source));
|
||||
g_return_if_fail (CAMEL_IS_FOLDER (dest));
|
||||
g_return_if_fail (uid != NULL);
|
||||
|
||||
if (source->parent_store == dest->parent_store) {
|
||||
return CF_CLASS (source)->copy_message_to (source, uid,
|
||||
dest, ex);
|
||||
} else
|
||||
return copy_message_to (source, uid, dest, ex);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
move_message_to (CamelFolder *source, const char *uid, CamelFolder *dest,
|
||||
CamelException *ex)
|
||||
|
||||
@ -162,6 +162,11 @@ typedef struct {
|
||||
const CamelMessageInfo * (*summary_get_by_uid) (CamelFolder *,
|
||||
const char *uid);
|
||||
|
||||
void (*copy_message_to) (CamelFolder *source,
|
||||
const char *uid,
|
||||
CamelFolder *destination,
|
||||
CamelException *ex);
|
||||
|
||||
void (*move_message_to) (CamelFolder *source,
|
||||
const char *uid,
|
||||
CamelFolder *destination,
|
||||
|
||||
@ -62,13 +62,10 @@ static void imap_init (CamelFolder *folder, CamelStore *parent_store,
|
||||
CamelException *ex);
|
||||
|
||||
static void imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
|
||||
#if 0
|
||||
static gboolean imap_exists (CamelFolder *folder, CamelException *ex);
|
||||
static gboolean imap_delete (CamelFolder *folder, gboolean recurse, CamelException *ex);
|
||||
static gboolean imap_delete_messages (CamelFolder *folder, CamelException *ex);
|
||||
#endif
|
||||
static gint imap_get_message_count (CamelFolder *folder, CamelException *ex);
|
||||
static void imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
|
||||
static void imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex);
|
||||
static void imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex);
|
||||
static GPtrArray *imap_get_uids (CamelFolder *folder, CamelException *ex);
|
||||
static gboolean imap_parse_subfolder_line (gchar *buf, gchar **flags, gchar **sep, gchar **folder);
|
||||
static GPtrArray *imap_get_subfolder_names (CamelFolder *folder, CamelException *ex);
|
||||
@ -79,13 +76,6 @@ static CamelMimeMessage *imap_get_message_by_uid (CamelFolder *folder, const gch
|
||||
|
||||
static void imap_expunge (CamelFolder *folder, CamelException *ex);
|
||||
|
||||
#if 0
|
||||
static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message,
|
||||
CamelFolder *dest_folder, CamelException *ex);
|
||||
static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message,
|
||||
CamelException *ex);
|
||||
#endif
|
||||
|
||||
static void imap_delete_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex);
|
||||
|
||||
static const CamelMessageInfo *imap_summary_get_by_uid (CamelFolder *f, const char *uid);
|
||||
@ -126,6 +116,8 @@ camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class)
|
||||
camel_folder_class->get_message_by_uid = imap_get_message_by_uid;
|
||||
camel_folder_class->append_message = imap_append_message;
|
||||
camel_folder_class->delete_message_by_uid = imap_delete_message_by_uid;
|
||||
camel_folder_class->copy_message_to = imap_copy_message_to;
|
||||
camel_folder_class->move_message_to = imap_move_message_to;
|
||||
|
||||
camel_folder_class->get_summary = imap_get_summary;
|
||||
camel_folder_class->summary_get_by_uid = imap_summary_get_by_uid;
|
||||
@ -453,8 +445,6 @@ imap_get_message_count (CamelFolder *folder, CamelException *ex)
|
||||
return imap_folder->count;
|
||||
}
|
||||
|
||||
/* TODO: Optimize this later - there may be times when moving/copying a message from the
|
||||
same IMAP store in which case we'd want to use IMAP's COPY command */
|
||||
static void
|
||||
imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex)
|
||||
{
|
||||
@ -510,6 +500,39 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
|
||||
g_free (folder_path);
|
||||
}
|
||||
|
||||
static void
|
||||
imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
|
||||
{
|
||||
CamelStore *store = CAMEL_STORE (source->parent_store);
|
||||
CamelURL *url = CAMEL_SERVICE (store)->url;
|
||||
char *result, *folder_path;
|
||||
int status;
|
||||
|
||||
if (url && url->path && *(url->path + 1) && strcmp (destination->full_name, "INBOX"))
|
||||
folder_path = g_strdup_printf ("%s/%s", url->path + 1, destination->full_name);
|
||||
else
|
||||
folder_path = g_strdup (destination->full_name);
|
||||
|
||||
status = camel_imap_command (CAMEL_IMAP_STORE (store), NULL, &result,
|
||||
"COPY %s %s", uid, folder_path);
|
||||
|
||||
if (status != CAMEL_IMAP_OK) {
|
||||
CamelService *service = CAMEL_SERVICE (store);
|
||||
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
|
||||
"Could not COPY message %s to %s on IMAP server %s: %s.",
|
||||
uid, folder_path, service->url->host,
|
||||
status == CAMEL_IMAP_ERR ? result :
|
||||
"Unknown error");
|
||||
g_free (result);
|
||||
g_free (folder_path);
|
||||
return;
|
||||
}
|
||||
|
||||
g_free (result);
|
||||
g_free (folder_path);
|
||||
}
|
||||
|
||||
/* FIXME: Duplication of code! */
|
||||
static void
|
||||
imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user