Changeset 3448

Show
Ignore:
Timestamp:
03/03/08 13:20:09
Author:
pvanhoof
Message:

Fixed filename= encoding

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.c

    r2950 r3448  
    3434#include <sys/stat.h> 
    3535#include <sys/types.h> 
     36 
     37#include <zlib.h> 
    3638 
    3739#include <glib.h> 
     
    799801 
    800802 
     803 
     804ssize_t 
     805camel_read_socket_compress (int fd, char *buf, size_t n) 
     806{ 
     807 
     808        ssize_t nread; 
     809        int cancel_fd; 
     810 
     811        if (camel_operation_cancel_check (NULL)) { 
     812                errno = EINTR; 
     813                return -1; 
     814        } 
     815#ifndef G_OS_WIN32 
     816        cancel_fd = camel_operation_cancel_fd (NULL); 
     817#else 
     818        cancel_fd = -1; 
     819#endif 
     820 
     821        cancel_fd = -1; 
     822 
     823        if (cancel_fd == -1) { 
     824 
     825                z_stream zst; 
     826                int err; 
     827                Byte *output; 
     828                char tbuf[1000000]; 
     829 
     830                zst.zalloc = (alloc_func) NULL; 
     831                zst.zfree = (free_func) Z_NULL; 
     832                err = inflateInit2_(&zst, -15, "1.2.3", sizeof (zst)); 
     833 
     834                zst.avail_out = 1000000; 
     835                output = (Byte *) malloc(zst.avail_out); 
     836 
     837                ssize_t nread; 
     838 
     839                int errnosav, flags, fdmax; 
     840                fd_set rdset; 
     841                struct timeval tv; 
     842                int res; 
     843 
     844                flags = fcntl (fd, F_GETFL); 
     845                fcntl (fd, F_SETFL, flags | O_NONBLOCK); 
     846 
     847 
     848                        FD_ZERO (&rdset); 
     849                        FD_SET (fd, &rdset); 
     850                        fdmax = fd + 1; 
     851                        tv.tv_sec = BLOCKING_READ_TIMEOUT; 
     852                        tv.tv_usec = 0; 
     853                        nread = -1; 
     854 
     855                        res = select(fdmax, &rdset, 0, 0, &tv); 
     856                        if (res == -1) 
     857                                ; 
     858                        else if (res == 0) 
     859                                errno = ETIMEDOUT; 
     860                        else { 
     861                                nread = read (fd, tbuf, n); 
     862 
     863                                printf ("%d\n", nread); 
     864 
     865                                zst.next_out = (Byte *) output; 
     866                                zst.next_in = (Byte *) tbuf; 
     867                                zst.avail_in = nread; 
     868 
     869                                err=inflate(&zst, Z_FINISH); 
     870                                err=inflateEnd(&zst); 
     871 
     872                                memcpy (buf, output, zst.total_out); 
     873                                nread = zst.total_out; 
     874                                //free (output); 
     875 
     876                                printf ("%s (%s) (%d v. %d -- %d)\n", output, buf, err, Z_OK, zst.total_out); 
     877 
     878                        } 
     879 
     880                errnosav = errno; 
     881                fcntl (fd, F_SETFL, flags); 
     882                errno = errnosav; 
     883 
     884 
     885        } else { 
     886#ifndef G_OS_WIN32 
     887                int errnosav, flags, fdmax; 
     888                fd_set rdset; 
     889 
     890                flags = fcntl (fd, F_GETFL); 
     891                fcntl (fd, F_SETFL, flags | O_NONBLOCK); 
     892 
     893                do { 
     894                        struct timeval tv; 
     895                        int res; 
     896 
     897                        FD_ZERO (&rdset); 
     898                        FD_SET (fd, &rdset); 
     899                        FD_SET (cancel_fd, &rdset); 
     900                        fdmax = MAX (fd, cancel_fd) + 1; 
     901                        tv.tv_sec = BLOCKING_READ_TIMEOUT; 
     902                        tv.tv_usec = 0; 
     903                        nread = -1; 
     904 
     905                        res = select(fdmax, &rdset, 0, 0, &tv); 
     906                        if (res == -1) 
     907                                ; 
     908                        else if (res == 0) 
     909                                errno = ETIMEDOUT; 
     910                        else if (FD_ISSET (cancel_fd, &rdset)) { 
     911                                errno = EINTR; 
     912                                goto failed; 
     913                        } else { 
     914                                do { 
     915                                        nread = read (fd, buf, n); 
     916                                } while (nread == -1 && errno == EINTR); 
     917                        } 
     918                } while (nread == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); 
     919        failed: 
     920                errnosav = errno; 
     921                fcntl (fd, F_SETFL, flags); 
     922                errno = errnosav; 
     923#endif 
     924        } 
     925 
     926        return nread; 
     927 
     928} 
     929 
    801930ssize_t 
    802931camel_read_socket_nb (int fd, char *buf, size_t n) 
     
    8801009} 
    8811010 
     1011 
     1012 
     1013 
     1014ssize_t 
     1015camel_read_socket_nb_compress (int fd, char *buf, size_t n) 
     1016{ 
     1017#ifdef G_OS_WIN32 
     1018        g_critical ("Not supported on Windows"); 
     1019#endif 
     1020 
     1021        return camel_read_nb (fd, buf, n); 
     1022} 
    8821023 
    8831024 
     
    9931134 
    9941135 
     1136 
     1137ssize_t 
     1138camel_write_socket_compress (int fd, const char *buf, size_t n) 
     1139{ 
     1140        ssize_t w, written = 0; 
     1141        int cancel_fd; 
     1142 
     1143        if (camel_operation_cancel_check (NULL)) { 
     1144                errno = EINTR; 
     1145                return -1; 
     1146        } 
     1147#ifndef G_OS_WIN32 
     1148        cancel_fd = camel_operation_cancel_fd (NULL); 
     1149#else 
     1150        cancel_fd = -1; 
     1151#endif 
     1152 
     1153cancel_fd = -1; 
     1154 
     1155 
     1156        if (cancel_fd == -1) { 
     1157 
     1158                z_stream zst; 
     1159                int err; 
     1160                Byte *output; 
     1161 
     1162                zst.zalloc=(alloc_func)NULL; 
     1163                zst.zfree=(free_func)Z_NULL; 
     1164                err=deflateInit2_ (&zst, 9, 8, -15, 9, 0, "1.2.3", sizeof (zst)); 
     1165 
     1166                printf ("init: %d\n", err); 
     1167 
     1168                zst.avail_out = 1000000; 
     1169                output = (Byte *) malloc(zst.avail_out); 
     1170 
     1171                zst.next_out = (Byte *) output; 
     1172                zst.next_in = (Byte *) buf; 
     1173                zst.avail_in = n; 
     1174 
     1175                err=deflate(&zst, Z_FINISH); 
     1176                err=deflateEnd(&zst); 
     1177 
     1178                w = write (fd, output, zst.total_out); 
     1179 
     1180                //free (output); 
     1181 
     1182                printf ("%s (%d v. %d -- %d)\n", output, err, Z_OK, zst.total_out); 
     1183 
     1184        } else { 
     1185#ifndef G_OS_WIN32 
     1186                int errnosav, flags, fdmax; 
     1187                fd_set rdset, wrset; 
     1188 
     1189                flags = fcntl (fd, F_GETFL); 
     1190                fcntl (fd, F_SETFL, flags | O_NONBLOCK); 
     1191 
     1192                fdmax = MAX (fd, cancel_fd) + 1; 
     1193                do { 
     1194                        struct timeval tv; 
     1195                        int res; 
     1196 
     1197                        FD_ZERO (&rdset); 
     1198                        FD_ZERO (&wrset); 
     1199                        FD_SET (fd, &wrset); 
     1200                        FD_SET (cancel_fd, &rdset); 
     1201                        tv.tv_sec = BLOCKING_READ_TIMEOUT; 
     1202                        tv.tv_usec = 0; 
     1203                        w = -1; 
     1204 
     1205                        res = select (fdmax, &rdset, &wrset, 0, &tv); 
     1206                        if (res == -1) { 
     1207                                if (errno == EINTR) 
     1208                                        w = 0; 
     1209                        } else if (res == 0) 
     1210                                errno = ETIMEDOUT; 
     1211                        else if (FD_ISSET (cancel_fd, &rdset)) 
     1212                                errno = EINTR; 
     1213                        else { 
     1214                                do { 
     1215                                        w = write (fd, buf + written, n - written); 
     1216                                } while (w == -1 && errno == EINTR); 
     1217 
     1218                                if (w == -1) { 
     1219                                        if (errno == EAGAIN || errno == EWOULDBLOCK) 
     1220                                                w = 0; 
     1221                                } else 
     1222                                        written += w; 
     1223                        } 
     1224                } while (w != -1 && written < n); 
     1225 
     1226                errnosav = errno; 
     1227                fcntl (fd, F_SETFL, flags); 
     1228                errno = errnosav; 
     1229#endif 
     1230        } 
     1231 
     1232        if (w == -1) 
     1233                return -1; 
     1234 
     1235        return n; 
     1236 
     1237} 
     1238 
    9951239/** 
    9961240 * camel_file_util_savename: 
  • trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.h

    r3261 r3448  
    9090 
    9191ssize_t camel_write_socket (int fd, const char *buf, size_t n); 
    92  
    9392ssize_t camel_read_socket (int fd, char *buf, size_t n); 
    9493ssize_t camel_read_socket_nb (int fd, char *buf, size_t n); 
     94 
     95ssize_t camel_write_socket_compress (int fd, const char *buf, size_t n); 
     96ssize_t camel_read_socket_compress (int fd, char *buf, size_t n); 
     97ssize_t camel_read_socket_nb_compress (int fd, char *buf, size_t n); 
    9598 
    9699char *camel_file_util_savename(const char *filename); 
  • trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.c

    r3446 r3448  
    7272raw_enable_compress (CamelTcpStream *stream) 
    7373{ 
    74         g_print ("RAW COMPRESS enable request: not yet supported"); 
     74        CamelTcpStreamRaw *raw = (CamelTcpStreamRaw *) stream; 
     75        raw->compress = TRUE; 
    7576        return; 
    7677} 
     
    113114        CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object); 
    114115 
     116        stream->compress = FALSE; 
    115117        stream->sockfd = -1; 
    116118} 
     
    270272        CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 
    271273 
     274        if (raw->compress) 
     275                return camel_read_socket_compress (raw->sockfd, buffer, n); 
     276 
    272277        return camel_read_socket (raw->sockfd, buffer, n); 
    273278} 
     
    278283        CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 
    279284 
     285        if (raw->compress) 
     286                return camel_read_socket_nb_compress (raw->sockfd, buffer, n); 
     287 
    280288        return camel_read_socket_nb (raw->sockfd, buffer, n); 
    281289} 
     
    285293{ 
    286294        CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 
     295 
     296        if (raw->compress) 
     297                return camel_write_socket_compress (raw->sockfd, buffer, n); 
    287298 
    288299        return camel_write_socket (raw->sockfd, buffer, n); 
  • trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.h

    r2950 r3448  
    4242        int is_nonblocking; 
    4343#endif 
     44        gboolean compress; 
    4445}; 
    4546 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c

    r3445 r3448  
    10241024 
    10251025                if (store->capabilities & IMAP_CAPABILITY_COMPRESS) { 
    1026                         // response = camel_imap_command (store, NULL, ex, "COMPRESS DEFLATE"); 
    1027                         if (TRUE /* && response */) { 
     1026                        response = camel_imap_command (store, NULL, ex, "COMPRESS DEFLATE"); 
     1027                        if (response) { 
    10281028                                camel_tcp_stream_enable_compress (CAMEL_TCP_STREAM (tcp_stream)); 
    1029                                 // camel_imap_response_free_without_processing (store, response); 
     1029                                camel_imap_response_free_without_processing (store, response); 
    10301030                        } 
    10311031                } 
  • trunk/libtinymail-camel/tny-camel-mime-part-priv.h

    r2825 r3448  
    3232        CamelMimePart *part; 
    3333        gchar *cached_content_type; 
     34        gchar *cached_filename; 
    3435}; 
    3536 
  • trunk/libtinymail-camel/tny-camel-mime-part.c

    r3424 r3448  
    6363#include <camel/camel-mime-filter-windows.h> 
    6464 
     65#include <libedataserver/e-iconv.h> 
     66 
    6567static ssize_t camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stream); 
     68 
     69 
     70 
     71static char* 
     72decode_it_2 (CamelMimePart *part, const char *str, gboolean is_addr) 
     73{ 
     74        struct _camel_header_raw *h = part->headers; 
     75        const char *content, *charset = NULL; 
     76        CamelContentType *ct = NULL; 
     77 
     78        if (!str) 
     79                return NULL; 
     80         
     81        if ((content = camel_header_raw_find(&h, "Content-Type", NULL)) 
     82             && (ct = camel_content_type_decode(content)) 
     83             && (charset = camel_content_type_param(ct, "charset")) 
     84             && (g_ascii_strcasecmp(charset, "us-ascii") == 0)) 
     85                charset = NULL; 
     86 
     87        charset = charset ? e_iconv_charset_name (charset) : NULL; 
     88 
     89        while (isspace ((unsigned) *str)) 
     90                str++; 
     91 
     92        if (is_addr) { 
     93                char *ret; 
     94                struct _camel_header_address *addr; 
     95                addr = camel_header_address_decode (str, charset); 
     96                if (addr) { 
     97                        ret = camel_header_address_list_format (addr); 
     98                        camel_header_address_list_clear (&addr); 
     99                } else { 
     100                        ret = g_strdup (str); 
     101                } 
     102 
     103                if (ct) 
     104                        camel_content_type_unref (ct); 
     105 
     106                return ret; 
     107        } 
     108 
     109        if (ct) 
     110                camel_content_type_unref (ct); 
     111 
     112        return camel_header_decode_string (str, charset); 
     113} 
     114 
    66115 
    67116static void  
     
    9601009        g_mutex_lock (priv->part_lock); 
    9611010 
     1011        if (priv->cached_filename) 
     1012                g_free (priv->cached_filename); 
     1013        priv->cached_filename = NULL; 
     1014 
    9621015        if (priv->cached_content_type) 
    9631016                g_free (priv->cached_content_type); 
     
    10121065 
    10131066        g_mutex_lock (priv->part_lock); 
    1014         retval = camel_mime_part_get_filename (priv->part); 
    1015         g_mutex_unlock (priv->part_lock); 
    1016          
    1017         return retval; 
     1067        if (!priv->cached_filename) { 
     1068                const char *str = camel_mime_part_get_filename (priv->part); 
     1069 
     1070                if (!g_utf8_validate (str, strlen (str), NULL)) 
     1071                        priv->cached_filename = decode_it_2 (priv->part, str, FALSE); 
     1072                else 
     1073                        priv->cached_filename = g_strdup (str); 
     1074        } 
     1075        g_mutex_unlock (priv->part_lock); 
     1076 
     1077        return priv->cached_filename; 
    10181078} 
    10191079 
     
    11931253        g_mutex_lock (priv->part_lock); 
    11941254        camel_mime_part_set_content_type (priv->part, content_type); 
     1255 
     1256        if (priv->cached_filename) 
     1257                g_free (priv->cached_filename); 
     1258        priv->cached_filename = NULL; 
     1259 
    11951260        if (priv->cached_content_type) 
    11961261                g_free (priv->cached_content_type); 
    11971262        priv->cached_content_type = NULL; 
     1263 
    11981264        g_mutex_unlock (priv->part_lock); 
    11991265 
     
    12081274 
    12091275        g_mutex_lock (priv->part_lock); 
     1276 
     1277        if (priv->cached_filename) 
     1278                g_free (priv->cached_filename); 
     1279        priv->cached_filename = NULL; 
     1280 
    12101281        if (priv->cached_content_type) 
    12111282                g_free (priv->cached_content_type); 
    12121283        priv->cached_content_type = NULL; 
     1284 
    12131285        if (priv->part && CAMEL_IS_OBJECT (priv->part)) 
    12141286                camel_object_unref (CAMEL_OBJECT (priv->part)); 
     
    13511423        priv->part_lock = g_mutex_new (); 
    13521424 
     1425        priv->cached_filename = NULL; 
     1426        priv->cached_content_type = NULL; 
     1427 
    13531428        return; 
    13541429} 
  • trunk/libtinymailui-gtk/tny-gtk-msg-view.c

    r3436 r3448  
    455455        } else if (tny_mime_part_content_type_is (part, "image/*")) 
    456456        { 
     457                gboolean nf = FALSE; 
    457458                TnyMimePartView *image_view = tny_gtk_image_mime_part_view_new (priv->status_callback, priv->status_user_data); 
    458                 const gchar *desc = tny_mime_part_get_description (part); 
     459                gchar *desc = (gchar *) tny_mime_part_get_description (part); 
     460 
    459461                retval = tny_gtk_expander_mime_part_view_new (image_view); 
    460                 if (!desc) 
    461                         desc = _("Attached image"); 
     462                if (!desc) { 
     463                        const gchar *filen = tny_mime_part_get_filename (part); 
     464                        if (filen) { 
     465                                desc = g_strdup_printf (_("Attached image: %s"), filen); 
     466                                nf = TRUE; 
     467                        } else 
     468                                desc = _("Attached image"); 
     469                } 
    462470                gtk_expander_set_label (GTK_EXPANDER (retval), desc); 
     471                if (nf) 
     472                        g_free (desc); 
    463473        } else if (tny_mime_part_content_type_is (part, "multipart/*")) 
    464474        {