Changeset 3029

Show
Ignore:
Timestamp:
11/28/07 23:37:52
Author:
pvanhoof
Message:

2007-11-28 Philip Van Hoof <pvanhoof@gnome.org>

        • Several fixes. in the bodystructure parsing
        • Several fixes in the mime part handling
        • Changed the API of mime part viewers to have a status

callback.

        • This was a major API change in libtinymail and libtinymailui
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/pvanhoof/bs/ChangeLog

    r3011 r3029  
     12007-11-28  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Several fixes. in the bodystructure parsing 
     4        * Several fixes in the mime part handling 
     5        * Changed the API of mime part viewers to have a status 
     6        callback. 
     7 
     8        * This was a major API change in libtinymail and libtinymailui 
     9 
    1102007-11-27  Philip Van Hoof  <pvanhoof@gnome.org> 
    211 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-bs-mime-part.c

    r3015 r3029  
    3939#include <tny-stream-camel.h> 
    4040#include <tny-camel-stream.h> 
    41  
     41#include <tny-camel-folder.h> 
    4242#include <tny-fs-stream.h> 
    4343 
    4444static GObjectClass *parent_class = NULL; 
    45  
    46 #include "tny-camel-bs-mime-part-priv.h" 
    47 #include "tny-camel-bs-msg-priv.h" 
    48 #include "tny-camel-bs-msg-header-priv.h" 
    4945 
    5046 
     
    6056#include "camel/camel-stream-null.h" 
    6157#include "camel/camel-mime-filter-charset.h" 
     58#include "camel/camel-folder.h" 
     59 
     60#include "tny-camel-queue-priv.h" 
     61#include "tny-camel-folder-priv.h" 
     62#include "tny-camel-account-priv.h" 
     63#include "tny-camel-store-account-priv.h" 
     64#include "tny-camel-bs-mime-part-priv.h" 
     65#include "tny-camel-bs-msg-priv.h" 
     66#include "tny-camel-bs-msg-header-priv.h" 
     67#include "tny-session-camel-priv.h" 
     68 
     69#define TINYMAIL_ENABLE_PRIVATE_API 
     70#include "tny-common-priv.h" 
     71#undef TINYMAIL_ENABLE_PRIVATE_API 
     72 
     73 
    6274 
    6375static ssize_t 
     
    163175 
    164176static void  
     177decode_from_stream_to (TnyMimePart *self, TnyStream *from_stream, TnyStream *stream, gboolean binary, gboolean decode_text) 
     178{ 
     179        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self); 
     180 
     181        if (decode_text && camel_strcase_equal (priv->bodystructure->content.type, "TEXT"))  
     182        { 
     183                gchar *encoding = NULL; 
     184                gchar *charset = (gchar *) mimeparam_get_value_for (priv->bodystructure->content.params, "CHARSET"); 
     185                CamelStream *cfrom_stream = tny_stream_camel_new (from_stream); 
     186                CamelStream *cto_stream = tny_stream_camel_new (stream); 
     187 
     188                if (!binary) 
     189                        encoding = priv->bodystructure->encoding; 
     190 
     191                if (!charset) 
     192                        charset = "UTF-8"; 
     193 
     194                bs_camel_stream_format_text (cfrom_stream, cto_stream, charset, encoding); 
     195 
     196                camel_object_unref (cfrom_stream); 
     197                camel_object_unref (cto_stream); 
     198        } else { 
     199                if (binary) 
     200                        tny_stream_write_to_stream (from_stream, stream); 
     201                else { 
     202                        CamelStream *cfrom_stream = tny_stream_camel_new (from_stream); 
     203                        CamelStream *cto_stream = tny_stream_camel_new (stream); 
     204                        gchar *encoding = priv->bodystructure->encoding; 
     205 
     206                        decode_to_stream (cfrom_stream, cto_stream, encoding, FALSE); 
     207 
     208                        camel_object_unref (cfrom_stream); 
     209                        camel_object_unref (cto_stream); 
     210                } 
     211        } 
     212} 
     213 
     214static void  
    165215fetch_part (TnyMimePart *self, TnyStream *stream, gboolean decode_text) 
    166216{ 
    167217        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self); 
     218        GError *err = NULL; 
    168219 
    169220        if (priv->folder)  
    170221        { 
    171                 GError *err = NULL; 
    172222                gboolean binary = TRUE; 
    173223                TnyStream *from_stream; 
    174224 
    175225                /* binary = !camel_strcase_equal (priv->bodystructure->content.type, "TEXT"); */ 
    176  
    177226                from_stream = tny_camel_bs_msg_receive_strategy_start_receiving_part ( 
    178227                        priv->strat, priv->folder, TNY_CAMEL_BS_MIME_PART (self), &binary, &err); 
     
    181230                        g_warning ("Error while fetching part: %s", err->message); 
    182231                        g_error_free (err); 
    183                 } else { 
    184                          
    185                          
    186                         if (decode_text && camel_strcase_equal (priv->bodystructure->content.type, "TEXT"))  
    187                         { 
    188                                 gchar *encoding = NULL; 
    189                                 gchar *charset = (gchar *) mimeparam_get_value_for (priv->bodystructure->content.params, "CHARSET"); 
    190                                 CamelStream *cfrom_stream = tny_stream_camel_new (from_stream); 
    191                                 CamelStream *cto_stream = tny_stream_camel_new (stream); 
    192  
    193                                 if (!binary) 
    194                                         encoding = priv->bodystructure->encoding; 
    195  
    196                                 if (!charset) 
    197                                         charset = "UTF-8"; 
    198  
    199                                 bs_camel_stream_format_text (cfrom_stream, cto_stream, charset, encoding); 
    200  
    201                                 camel_object_unref (cfrom_stream); 
    202                                 camel_object_unref (cto_stream); 
    203                         } else { 
    204                                 if (binary) 
    205                                         tny_stream_write_to_stream (from_stream, stream); 
    206                                 else { 
    207                                         CamelStream *cfrom_stream = tny_stream_camel_new (from_stream); 
    208                                         CamelStream *cto_stream = tny_stream_camel_new (stream); 
    209                                         gchar *encoding = priv->bodystructure->encoding; 
    210  
    211                                         decode_to_stream (cfrom_stream, cto_stream, encoding, FALSE); 
    212  
    213                                         camel_object_unref (cfrom_stream); 
    214                                         camel_object_unref (cto_stream); 
    215                                 } 
    216                         } 
    217                 } 
     232                } else 
     233                        decode_from_stream_to (self, from_stream, stream, binary, decode_text); 
    218234 
    219235                if (from_stream) 
     
    375391} 
    376392 
     393 
     394 
     395typedef struct { 
     396        TnyCamelQueueable parent; 
     397 
     398        GObject *self, *stream; 
     399        TnyMimePartCallback callback; 
     400        TnyStatusCallback status_callback; 
     401        gpointer user_data; 
     402        GError *err; 
     403        gboolean binary; 
     404        TnyStream *from_stream; 
     405        TnyIdleStopper *stopper; 
     406        TnySessionCamel *session; 
     407} DecodeAsyncInfo; 
     408 
     409 
     410static void 
     411decode_async_destroyer (gpointer user_data) 
     412{ 
     413        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     414        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (info->self); 
     415        TnyCamelFolderPriv *fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (priv->folder); 
     416 
     417        _tny_camel_folder_unreason (fpriv); 
     418 
     419        g_object_unref (info->stream); 
     420        g_object_unref (info->self); 
     421        if (info->from_stream) 
     422                g_object_unref (info->from_stream); 
     423        if (info->err) 
     424                g_error_free (info->err); 
     425 
     426        tny_idle_stopper_destroy (info->stopper); 
     427        info->stopper = NULL; 
     428 
     429         
     430        return; 
     431} 
     432 
     433static gboolean 
     434decode_async_callback (gpointer user_data) 
     435{ 
     436        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     437 
     438        tny_lockable_lock (info->session->priv->ui_lock); 
     439 
     440        if (info->from_stream) { 
     441                decode_from_stream_to (TNY_MIME_PART (info->self),  
     442                        TNY_STREAM (info->from_stream), TNY_STREAM (info->stream), 
     443                         info->binary, TRUE); 
     444        } 
     445 
     446        if (info->callback) {  
     447                info->callback (TNY_MIME_PART (info->self), TNY_STREAM (info->stream), FALSE, info->err, info->user_data); 
     448        } 
     449 
     450        tny_lockable_unlock (info->session->priv->ui_lock); 
     451 
     452        return FALSE; 
     453} 
     454 
     455 
     456 
     457static void 
     458decode_async_cancelled_destroyer (gpointer user_data) 
     459{ 
     460        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     461        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (info->self); 
     462        TnyCamelFolderPriv *fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (priv->folder); 
     463 
     464        _tny_camel_folder_unreason (fpriv); 
     465        g_object_unref (info->stream); 
     466        g_object_unref (info->self); 
     467        if (info->err) 
     468                g_error_free (info->err); 
     469 
     470        tny_idle_stopper_destroy (info->stopper); 
     471        info->stopper = NULL; 
     472 
     473         
     474        return; 
     475} 
     476 
     477 
     478static gboolean 
     479decode_async_cancelled_callback (gpointer user_data) 
     480{ 
     481        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     482        if (info->callback) {  
     483                tny_lockable_lock (info->session->priv->ui_lock); 
     484                info->callback (TNY_MIME_PART (info->self), TNY_STREAM (info->stream), TRUE, info->err, info->user_data); 
     485                tny_lockable_unlock (info->session->priv->ui_lock); 
     486        } 
     487        return FALSE; 
     488} 
     489 
     490static void 
     491decode_async_status (struct _CamelOperation *op, const char *what, int sofar, int oftotal, void *user_data) 
     492{ 
     493        DecodeAsyncInfo *oinfo = user_data; 
     494        TnyProgressInfo *info = NULL; 
     495 
     496        info = tny_progress_info_new (G_OBJECT (oinfo->self), oinfo->status_callback,  
     497                TNY_FOLDER_STATUS, TNY_FOLDER_STATUS_CODE_GET_MSG, what, sofar,  
     498                oftotal, oinfo->stopper, oinfo->session->priv->ui_lock, oinfo->user_data); 
     499 
     500        g_idle_add_full (G_PRIORITY_HIGH, 
     501                tny_progress_info_idle_func, info, 
     502                tny_progress_info_destroy); 
     503 
     504        return; 
     505} 
     506 
     507 
     508static gpointer  
     509decode_async_thread (gpointer user_data) 
     510{ 
     511        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     512        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (info->self); 
     513        TnyCamelFolderPriv *fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (priv->folder); 
     514 
     515        g_static_rec_mutex_lock (fpriv->folder_lock); 
     516 
     517        _tny_camel_account_start_camel_operation (TNY_CAMEL_ACCOUNT (fpriv->account),  
     518                decode_async_status, info, "Getting part"); 
     519 
     520        /* binary = !camel_strcase_equal (priv->bodystructure->content.type, "TEXT"); */ 
     521        info->binary = TRUE; 
     522        info->from_stream = tny_camel_bs_msg_receive_strategy_start_receiving_part ( 
     523                priv->strat, priv->folder, TNY_CAMEL_BS_MIME_PART (info->self),  
     524                &info->binary, &info->err); 
     525 
     526        _tny_camel_account_stop_camel_operation (TNY_CAMEL_ACCOUNT (fpriv->account)); 
     527 
     528        g_static_rec_mutex_unlock (fpriv->folder_lock); 
     529 
     530        return NULL; 
     531} 
     532 
     533 
     534static void 
     535tny_camel_bs_mime_part_decode_to_stream_async (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data) 
     536{ 
     537        TNY_CAMEL_BS_MIME_PART_GET_CLASS (self)->decode_to_stream_async_func (self, stream, callback, status_callback, user_data); 
     538        return; 
     539} 
     540 
     541 
     542static void 
     543tny_camel_bs_mime_part_decode_to_stream_async_default (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data) 
     544{ 
     545        DecodeAsyncInfo *info = g_slice_new0 (DecodeAsyncInfo); 
     546        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self); 
     547        TnyCamelFolderPriv *fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (priv->folder); 
     548 
     549        info->err = NULL; 
     550        info->session = TNY_FOLDER_PRIV_GET_SESSION (fpriv); 
     551        info->self = g_object_ref (self); 
     552        info->stream = g_object_ref (stream); 
     553        info->callback = callback; 
     554        info->status_callback = status_callback; 
     555        info->user_data = user_data; 
     556        info->stopper = tny_idle_stopper_new (); 
     557 
     558        _tny_camel_folder_reason (fpriv); 
     559 
     560        _tny_camel_queue_launch (TNY_FOLDER_PRIV_GET_QUEUE (fpriv),  
     561                decode_async_thread,  
     562                decode_async_callback, 
     563                decode_async_destroyer,  
     564                decode_async_cancelled_callback, 
     565                decode_async_cancelled_destroyer,  
     566                NULL, 
     567                info, sizeof (DecodeAsyncInfo), __FUNCTION__); 
     568 
     569        return; 
     570} 
    377571 
    378572 
     
    753947        klass->get_header_pairs_func = tny_camel_bs_mime_part_get_header_pairs; 
    754948        klass->set_header_pair_func = tny_camel_bs_mime_part_set_header_pair; 
     949        klass->decode_to_stream_async_func = tny_camel_bs_mime_part_decode_to_stream_async; 
    755950 
    756951        return; 
     
    789984        class->get_header_pairs_func = tny_camel_bs_mime_part_get_header_pairs_default; 
    790985        class->set_header_pair_func = tny_camel_bs_mime_part_set_header_pair_default; 
     986        class->decode_to_stream_async_func = tny_camel_bs_mime_part_decode_to_stream_async_default; 
    791987 
    792988        object_class->finalize = tny_camel_bs_mime_part_finalize; 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-bs-mime-part.h

    r3011 r3029  
    7171        void (*get_header_pairs_func) (TnyMimePart *self, TnyList *list); 
    7272        void (*set_header_pair_func) (TnyMimePart *self, const gchar *name, const gchar *value); 
     73        void (*decode_to_stream_async_func) (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data); 
    7374}; 
    7475 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c

    r3013 r3029  
    8989        } else { 
    9090                int fd = open (filename, 0); 
    91                 retval = tny_fs_stream_new (fd); 
     91 
     92                if (fd == -1) { 
     93                        g_set_error (err, TNY_FOLDER_ERROR,  
     94                                TNY_FOLDER_ERROR_GET_MSG, 
     95                                "Can't open %s for reading", filename); 
     96                        retval = NULL; 
     97                } else 
     98                        retval = tny_fs_stream_new (fd); 
    9299        } 
    93100 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-folder.c

    r3007 r3029  
    907907                g_error_free (info->err); 
    908908 
     909        tny_idle_stopper_destroy (info->stopper); 
     910        info->stopper = NULL; 
     911 
    909912        return; 
    910913} 
     
    15201523        if (info->err) 
    15211524                g_error_free (info->err); 
     1525 
     1526        tny_idle_stopper_destroy (info->stopper); 
     1527        info->stopper = NULL; 
    15221528 
    15231529        return; 
     
    17271733        if (info->err) 
    17281734                g_error_free (info->err); 
     1735 
     1736        tny_idle_stopper_destroy (info->stopper); 
     1737        info->stopper = NULL; 
     1738 
    17291739        return; 
    17301740} 
     
    19541964        g_object_unref (info->self); 
    19551965        g_object_unref (info->headers); 
     1966 
    19561967        return; 
    19571968} 
     
    22422253        if (info->err) 
    22432254                g_error_free (info->err); 
     2255 
     2256        tny_idle_stopper_destroy (info->stopper); 
     2257        info->stopper = NULL; 
    22442258 
    22452259        return; 
     
    32723286        g_object_unref (info->into); 
    32733287 
     3288        tny_idle_stopper_destroy (info->stopper); 
     3289        info->stopper = NULL; 
     3290 
    32743291        return; 
    32753292} 
     
    38563873        if (info->err) 
    38573874                g_error_free (info->err); 
     3875 
     3876        tny_idle_stopper_destroy (info->stopper); 
     3877        info->stopper = NULL; 
    38583878 
    38593879        return; 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-mime-part.c

    r3028 r3029  
    196196} 
    197197 
     198typedef struct { 
     199        GObject *self, *stream; 
     200        TnyMimePartCallback callback; 
     201        gpointer user_data; 
     202        GError *err; 
     203} DecodeAsyncInfo; 
     204 
     205 
     206static void 
     207decode_async_destroyer (gpointer user_data) 
     208{ 
     209        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     210        /* thread reference */ 
     211        g_object_unref (info->self); 
     212        g_object_unref (info->stream); 
     213        if (info->err) 
     214                g_error_free (info->err); 
     215        g_slice_free (DecodeAsyncInfo, info); 
     216        return; 
     217} 
     218 
     219static gboolean 
     220decode_async_callback (gpointer user_data) 
     221{ 
     222        DecodeAsyncInfo *info = (DecodeAsyncInfo *) user_data; 
     223        if (info->callback) {  
     224                /* TODO: tny_lockable_lock (priv->ui_locker); */ 
     225                info->callback (TNY_MIME_PART (info->self), TNY_STREAM (info->stream),  
     226                        FALSE, info->err, info->user_data); 
     227                /* TODO: tny_lockable_unlock (priv->ui_locker); */ 
     228        } 
     229        return FALSE; 
     230} 
     231 
     232/* This one is just to fulfil the API requirements */ 
     233 
     234static void 
     235tny_camel_mime_part_decode_to_stream_async (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data) 
     236{ 
     237        TNY_CAMEL_MIME_PART_GET_CLASS (self)->decode_to_stream_async_func (self, stream, callback, status_callback, user_data); 
     238        return; 
     239} 
     240 
     241static void 
     242tny_camel_mime_part_decode_to_stream_async_default (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data) 
     243{ 
     244        DecodeAsyncInfo *info = g_slice_new0 (DecodeAsyncInfo); 
     245 
     246        tny_mime_part_decode_to_stream (self, stream); 
     247 
     248        info->self = g_object_ref (self); 
     249        info->stream = g_object_ref (stream); 
     250        info->callback = callback; 
     251        info->user_data = user_data; 
     252        info->err = NULL; 
     253 
     254        g_idle_add_full (G_PRIORITY_HIGH,  
     255                                decode_async_callback,  
     256                                info, decode_async_destroyer); 
     257 
     258        return; 
     259} 
    198260 
    199261 
     
    10081070        klass->get_header_pairs_func = tny_camel_mime_part_get_header_pairs; 
    10091071        klass->set_header_pair_func = tny_camel_mime_part_set_header_pair; 
    1010  
     1072        klass->decode_to_stream_async_func = tny_camel_mime_part_decode_to_stream_async; 
    10111073        return; 
    10121074} 
     
    10441106        class->get_header_pairs_func = tny_camel_mime_part_get_header_pairs_default; 
    10451107        class->set_header_pair_func = tny_camel_mime_part_set_header_pair_default; 
     1108        class->decode_to_stream_async_func = tny_camel_mime_part_decode_to_stream_async_default; 
    10461109 
    10471110        object_class->finalize = tny_camel_mime_part_finalize; 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-mime-part.h

    r2825 r3029  
    7373        void (*get_header_pairs_func) (TnyMimePart *self, TnyList *list); 
    7474        void (*set_header_pair_func) (TnyMimePart *self, const gchar *name, const gchar *value); 
     75        void (*decode_to_stream_async_func) (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data); 
     76 
    7577}; 
    7678 
  • devel/pvanhoof/bs/libtinymail-camel/tny-camel-store-account.c

    r2999 r3029  
    12971297        if (info->err) 
    12981298                g_error_free (info->err); 
     1299 
    12991300        return; 
    13001301} 
  • devel/pvanhoof/bs/libtinymail/tny-mime-part.c

    r2825 r3029  
    3838 *  
    3939 * Set a header pair (name: value) or delete a header (use NULL as value). 
     40 * 
     41 * Note that not all TnyMimePart instances are writable. Only when creating 
     42 * a new message will the instance be guaranteed to be writable. This is a 
     43 * writing operation. 
    4044 * 
    4145 * Example: 
     
    148152 * Add a mime-part to @self. 
    149153 * 
     154 * Note that not all TnyMimePart instances are writable. Only when creating 
     155 * a new message will the instance be guaranteed to be writable. This is a 
     156 * writing operation. 
     157 * 
    150158 * Return value: The id of the added mime-part 
    151  * 
    152159 **/ 
    153160gint 
     
    171178 * Delete a mime-part from @self 
    172179 * 
     180 * Note that not all TnyMimePart instances are writable. Only when creating 
     181 * a new message will the instance be guaranteed to be writable. This is a 
     182 * writing operation. 
    173183 **/ 
    174184void 
     
    236246 * Set the content location of @self. 
    237247 * 
     248 * Note that not all TnyMimePart instances are writable. Only when creating 
     249 * a new message will the instance be guaranteed to be writable. This is a 
     250 * writing operation. 
    238251 **/ 
    239252void 
     
    257270 * Set the description of @self. 
    258271 * 
     272 * Note that not all TnyMimePart instances are writable. Only when creating 
     273 * a new message will the instance be guaranteed to be writable. This is a 
     274 * writing operation. 
    259275 **/ 
    260276void 
     
    278294 * Set the content id of @self. 
    279295 * 
     296 * Note that not all TnyMimePart instances are writable. Only when creating 
     297 * a new message will the instance be guaranteed to be writable. This is a 
     298 * writing operation. 
    280299 **/ 
    281300void 
     
    298317 * Set the message as purged in cache 
    299318 * 
     319 * This is not a writing operation. Although it might change the content of a 
     320 * message for a user who's not connected with the server where @self originates 
     321 * from. 
     322 * 
     323 * Using the tny_msg_rewrite_cache API on a message instance will rewrite its  
     324 * purged mime parts with an empty body (saving storage space). The storage  
     325 * space is recovered after using tny_msg_rewrite_cache. Only setting a mime  
     326 * part to purged might not remove it. 
     327 * 
     328 * There is no guarantee about what happens with a purged mime part internally  
     329 * (it might get destroyed or become unuseful more early than the call to 
     330 * tny_msg_rewrite_cache). 
    300331 **/ 
    301332void 
     
    318349 * Set the filename of @self. 
    319350 * 
     351 * Note that not all TnyMimePart instances are writable. Only when creating 
     352 * a new message will the instance be guaranteed to be writable. This is a 
     353 * writing operation. 
    320354 **/ 
    321355void 
     
    339373 * Set the content type of @self. Formatted as "type/subtype" 
    340374 * 
     375 * Note that not all TnyMimePart instances are writable. Only when creating 
     376 * a new message will the instance be guaranteed to be writable. This is a 
     377 * writing operation. 
    341378 **/ 
    342379void 
     
    362399 * 
    363400 * Return value: the filename of a mime part as a read-only string 
    364  * 
    365401 **/ 
    366402const gchar* 
     
    390426 * 
    391427 * Return value: the content-id of a mime part as a read-only string 
    392  * 
    393428 **/ 
    394429const gchar* 
     
    418453 * 
    419454 * Return value: a #gboolean 
    420  * 
    421455 **/ 
    422456gboolean 
     
    469503 * 
    470504 * Return value: the content-location of a mime part as a read-only string 
    471  * 
    472505 **/ 
    473506const gchar* 
     
    497530 * Efficiently write the content of @self to a stream. This will not read the  
    498531 * data of the part in a memory buffer. In stead it will read the part data while 
    499  * already writing it to the stream efficiently. 
     532 * already writing it to the stream efficiently. Although there is no guarantee 
     533 * about the memory usage either (just that it's the most efficient way). 
    500534 * 
    501535 * You probably want to utilise the tny_mime_part_decode_to_stream 
    502536 * method in stead of this one. This method will not attempt to decode the 
    503537 * mime part. Mime parts are usually encoded in E-mails. 
     538 * 
     539 * When the mime part was received in BINARY mode from an IMAP server, then this 
     540 * API has mostly the same effect as the tny_mime_part_decode_to_stream: You  
     541 * will get a non-encoded version of the data. A small difference will be that 
     542 * the tny_mime_part_decode_to_stream will decode certain special characters in 
     543 * TEXT/* mime parts (character set encoding) to UTF-8. 
     544 * 
     545 * However. A larger difference happens with binary mime parts that where not 
     546 * retrieved using BINARY. For those this API will give you the encoded data 
     547 * as is. This means that you will get a stream spitting out for example BASE64 
     548 * data. 
    504549 *  
    505550 * Example: 
     
    537582 * Efficiently decode @self to a stream. This will not read the data of the 
    538583 * part in a memory buffer. In stead it will read the part data while already 
    539  * writing it to the stream efficiently. 
     584 * writing it to the stream efficiently. Although there is no guarantee 
     585 * about the memory usage either (just that it's the most efficient way). 
     586 * 
     587 * You will always get the decoded version of the data of @self. When your part 
     588 * get received in BINARY from an IMAP server, then nothing will really happen 
     589 * with your data (it will be streamed to you the way it got received). If we 
     590 * received using BODY and the data is encoded in a known encoding (BASE65, 
     591 * QUOTED-PRINTED, UUENCODED), the data will be decoded before delivered. TEXT/* 
     592 * mime parts will also enjoy character set decoding. 
     593 * 
     594 * In short will this API prepare the cookie and deliver it to your stream. It's 
     595 * most likely the one that you want to use. If you are planning to nevertheless 
     596 * use the tny_mime_part_write_to_stream API, then please know and understand 
     597 * what you are doing. 
     598 * 
     599 * It's possible that this API receives information from the service. If you  
     600 * don't want to block on this, use tny_mime_part_decode_to_stream_async. 
    540601 * 
    541602 * Example: 
     
    565626        return; 
    566627} 
     628 
     629/** 
     630 * tny_mime_part_decode_to_stream_async: 
     631 * @self: a #TnyMimePart object 
     632 * @stream: a #TnyMsgStream stream 
     633 * @callback: a #TnyMimePartCallback callback 
     634 * @status_callback: a #TnyStatusCallback callback 
     635 * @user_data: user data for @callback 
     636 * 
     637 * This method does the same as tny_mime_part_decode_to_stream. It just does  
     638 * everything asynchronous and calls you back when finished. 
     639 */ 
     640void 
     641tny_mime_part_decode_to_stream_async (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data) 
     642{ 
     643#ifdef DBC /* require */ 
     644        g_assert (TNY_IS_MIME_PART (self)); 
     645        g_assert (stream); 
     646        g_assert (TNY_IS_STREAM (stream)); 
     647        g_assert (TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_async_func != NULL); 
     648#endif 
     649 
     650        TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_async_func (self, stream, callback, status_callback, user_data); 
     651        return; 
     652} 
     653 
     654 
    567655/** 
    568656 * tny_mime_part_construct_from_stream: 
  • devel/pvanhoof/bs/libtinymail/tny-mime-part.h

    r2825 r3029  
    6868        void (*get_header_pairs_func) (TnyMimePart *self, TnyList *list); 
    6969        void (*set_header_pair_func) (TnyMimePart *self, const gchar *name, const gchar *value); 
     70        void (*decode_to_stream_async_func) (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data); 
    7071}; 
    7172 
     
    9596void tny_mime_part_get_header_pairs (TnyMimePart *self, TnyList *list); 
    9697void tny_mime_part_set_header_pair (TnyMimePart *self, const gchar *name, const gchar *value); 
     98void tny_mime_part_decode_to_stream_async (TnyMimePart *self, TnyStream *stream, TnyMimePartCallback callback, TnyStatusCallback status_callback, gpointer user_data); 
    9799 
    98100G_END_DECLS 
  • devel/pvanhoof/bs/libtinymail/tny-shared.h

    r2825 r3029  
    9999typedef void (*TnyForgetPassFunc) (TnyAccount *self); 
    100100typedef void (*TnyFolderCallback) (TnyFolder *self, gboolean canceled, GError *err, gpointer user_data); 
     101typedef void (*TnyMimePartCallback) (TnyMimePart *self, TnyStream *stream, gboolean canceled, GError *err, gpointer user_data); 
    101102typedef void (*TnyGetHeadersCallback) (TnyFolder *self, gboolean canceled, TnyList *headers, GError *err, gpointer user_data); 
    102103typedef void (*TnyGetMsgCallback) (TnyFolder *folder, gboolean canceled, TnyMsg *msg, GError *err, gpointer user_data); 
  • devel/pvanhoof/bs/libtinymailui-gtk/tny-gtk-image-mime-part-view.c

    r2975 r3029  
    5151{ 
    5252        TnyMimePart *part; 
     53        TnyStatusCallback status_callback; 
     54        gpointer status_user_data; 
    5355}; 
    5456 
     
    7880 
    7981static void  
     82on_mime_part_decoded (TnyMimePart *part, TnyStream *dest, gboolean canceled, GError *err, gpointer user_data) 
     83{ 
     84        TnyMimePartView *self = (TnyMimePartView *) user_data; 
     85        GdkPixbuf *pixbuf; 
     86        tny_stream_reset (dest); 
     87        pixbuf = tny_gtk_pixbuf_stream_get_pixbuf (TNY_GTK_PIXBUF_STREAM (dest)); 
     88        gtk_image_set_from_pixbuf (GTK_IMAGE (self), pixbuf); 
     89        g_object_unref (self); 
     90} 
     91 
     92static void  
     93on_status (GObject *part, TnyStatus *status, gpointer user_data) 
     94{ 
     95        TnyMimePartView *self = (TnyMimePartView *) user_data; 
     96        TnyGtkImageMimePartViewPriv *priv = TNY_GTK_IMAGE_MIME_PART_VIEW_GET_PRIVATE (self); 
     97        if (priv->status_callback) 
     98                priv->status_callback (self, status, priv->status_user_data); 
     99        return; 
     100} 
     101 
     102static void  
    80103tny_gtk_image_mime_part_view_set_part_default (TnyMimePartView *self, TnyMimePart *part) 
    81104{ 
     
    84107        g_assert (TNY_IS_MIME_PART (part)); 
    85108 
    86         if (G_LIKELY (priv->part)
     109        if (priv->part
    87110                g_object_unref (priv->part); 
    88111 
    89         if (part) 
    90         { 
    91                 TnyStream *dest; 
    92                 GdkPixbuf *pixbuf; 
    93  
    94                 dest = tny_gtk_pixbuf_stream_new (tny_mime_part_get_content_type (part)); 
    95  
     112        if (part) { 
     113                TnyStream *dest = tny_gtk_pixbuf_stream_new (tny_mime_part_get_content_type (part)); 
    96114                tny_stream_reset (dest); 
    97                 tny_mime_part_decode_to_stream (part, dest); 
    98                 tny_stream_reset (dest); 
    99  
    100                 pixbuf = tny_gtk_pixbuf_stream_get_pixbuf (TNY_GTK_PIXBUF_STREAM (dest)); 
    101                 gtk_image_set_from_pixbuf (GTK_IMAGE (self), pixbuf); 
    102  
     115                tny_mime_part_decode_to_stream_async (part, dest, on_mime_part_decoded,  
     116                                on_status, g_object_ref (self)); 
    103117                g_object_unref (dest); 
    104  
    105118                priv->part = g_object_ref (part); 
    106119        } 
     
    124137/** 
    125138 * tny_gtk_image_mime_part_view_new: 
     139 * @status_callback: a #TnyStatusCallback for when status information happens 
     140 * @status_user_data: user data for @status_callback 
    126141 * 
    127142 * Create a new #TnyMimePartView for Gtk+ 
     
    130145 **/ 
    131146TnyMimePartView* 
    132 tny_gtk_image_mime_part_view_new (void
     147tny_gtk_image_mime_part_view_new (TnyStatusCallback status_callback, gpointer status_user_data
    133148{ 
    134149        TnyGtkImageMimePartView *self = g_object_new (TNY_TYPE_GTK_IMAGE_MIME_PART_VIEW, NULL); 
     150        TnyGtkImageMimePartViewPriv *priv = TNY_GTK_IMAGE_MIME_PART_VIEW_GET_PRIVATE (self); 
     151 
     152        priv->status_callback = status_callback; 
     153        priv->status_user_data = status_user_data; 
    135154 
    136155        return TNY_MIME_PART_VIEW (self); 
     
    143162        TnyGtkImageMimePartViewPriv *priv = TNY_GTK_IMAGE_MIME_PART_VIEW_GET_PRIVATE (self); 
    144163 
     164        priv->status_callback = NULL; 
     165        priv->status_user_data = NULL; 
    145166 
    146167        return; 
     
    153174        TnyGtkImageMimePartViewPriv *priv = TNY_GTK_IMAGE_MIME_PART_VIEW_GET_PRIVATE (self); 
    154175 
    155         if (G_LIKELY (priv->part)
    156                 g_object_unref (G_OBJECT (priv->part)); 
     176        if (priv->part
     177                g_object_unref (priv->part); 
    157178 
    158179        (*parent_class->finalize) (object); 
  • devel/pvanhoof/bs/libtinymailui-gtk/tny-gtk-image-mime-part-view.h

    r2975 r3029  
    5959 
    6060GType tny_gtk_image_mime_part_view_get_type (void); 
    61 TnyMimePartView* tny_gtk_image_mime_part_view_new (void); 
     61TnyMimePartView* tny_gtk_image_mime_part_view_new (TnyStatusCallback status_callback, gpointer status_user_data); 
    6262 
    6363G_END_DECLS 
  • devel/pvanhoof/bs/libtinymailui-gtk/tny-gtk-mime-part-save-strategy.c

    r2825 r3029  
    4747static GObjectClass *parent_class = NULL; 
    4848 
     49typedef struct _TnyGtkMimePartSaveStrategyPriv TnyGtkMimePartSaveStrategyPriv; 
     50 
     51struct _TnyGtkMimePartSaveStrategyPriv 
     52{ 
     53        TnyStatusCallback status_callback; 
     54        gpointer status_user_data; 
     55}; 
     56 
    4957#define TNY_GTK_MIME_PART_SAVE_STRATEGY_GET_PRIVATE(o) \ 
    5058        (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_GTK_MIME_PART_SAVE_STRATEGY, TnyGtkMimePartSaveStrategy