Changeset 3448
- Timestamp:
- 03/03/08 13:20:09
- Files:
-
- trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.c (modified) (4 diffs)
- trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.h (modified) (1 diff)
- trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.c (modified) (5 diffs)
- trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.h (modified) (1 diff)
- trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c (modified) (1 diff)
- trunk/libtinymail-camel/tny-camel-mime-part-priv.h (modified) (1 diff)
- trunk/libtinymail-camel/tny-camel-mime-part.c (modified) (6 diffs)
- trunk/libtinymailui-gtk/tny-gtk-msg-view.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.c
r2950 r3448 34 34 #include <sys/stat.h> 35 35 #include <sys/types.h> 36 37 #include <zlib.h> 36 38 37 39 #include <glib.h> … … 799 801 800 802 803 804 ssize_t 805 camel_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 801 930 ssize_t 802 931 camel_read_socket_nb (int fd, char *buf, size_t n) … … 880 1009 } 881 1010 1011 1012 1013 1014 ssize_t 1015 camel_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 } 882 1023 883 1024 … … 993 1134 994 1135 1136 1137 ssize_t 1138 camel_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 1153 cancel_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 995 1239 /** 996 1240 * camel_file_util_savename: trunk/libtinymail-camel/camel-lite/camel/camel-file-utils.h
r3261 r3448 90 90 91 91 ssize_t camel_write_socket (int fd, const char *buf, size_t n); 92 93 92 ssize_t camel_read_socket (int fd, char *buf, size_t n); 94 93 ssize_t camel_read_socket_nb (int fd, char *buf, size_t n); 94 95 ssize_t camel_write_socket_compress (int fd, const char *buf, size_t n); 96 ssize_t camel_read_socket_compress (int fd, char *buf, size_t n); 97 ssize_t camel_read_socket_nb_compress (int fd, char *buf, size_t n); 95 98 96 99 char *camel_file_util_savename(const char *filename); trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.c
r3446 r3448 72 72 raw_enable_compress (CamelTcpStream *stream) 73 73 { 74 g_print ("RAW COMPRESS enable request: not yet supported"); 74 CamelTcpStreamRaw *raw = (CamelTcpStreamRaw *) stream; 75 raw->compress = TRUE; 75 76 return; 76 77 } … … 113 114 CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object); 114 115 116 stream->compress = FALSE; 115 117 stream->sockfd = -1; 116 118 } … … 270 272 CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 271 273 274 if (raw->compress) 275 return camel_read_socket_compress (raw->sockfd, buffer, n); 276 272 277 return camel_read_socket (raw->sockfd, buffer, n); 273 278 } … … 278 283 CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 279 284 285 if (raw->compress) 286 return camel_read_socket_nb_compress (raw->sockfd, buffer, n); 287 280 288 return camel_read_socket_nb (raw->sockfd, buffer, n); 281 289 } … … 285 293 { 286 294 CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); 295 296 if (raw->compress) 297 return camel_write_socket_compress (raw->sockfd, buffer, n); 287 298 288 299 return camel_write_socket (raw->sockfd, buffer, n); trunk/libtinymail-camel/camel-lite/camel/camel-tcp-stream-raw.h
r2950 r3448 42 42 int is_nonblocking; 43 43 #endif 44 gboolean compress; 44 45 }; 45 46 trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
r3445 r3448 1024 1024 1025 1025 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) { 1028 1028 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); 1030 1030 } 1031 1031 } trunk/libtinymail-camel/tny-camel-mime-part-priv.h
r2825 r3448 32 32 CamelMimePart *part; 33 33 gchar *cached_content_type; 34 gchar *cached_filename; 34 35 }; 35 36 trunk/libtinymail-camel/tny-camel-mime-part.c
r3424 r3448 63 63 #include <camel/camel-mime-filter-windows.h> 64 64 65 #include <libedataserver/e-iconv.h> 66 65 67 static ssize_t camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stream); 68 69 70 71 static char* 72 decode_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 66 115 67 116 static void … … 960 1009 g_mutex_lock (priv->part_lock); 961 1010 1011 if (priv->cached_filename) 1012 g_free (priv->cached_filename); 1013 priv->cached_filename = NULL; 1014 962 1015 if (priv->cached_content_type) 963 1016 g_free (priv->cached_content_type); … … 1012 1065 1013 1066 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; 1018 1078 } 1019 1079 … … 1193 1253 g_mutex_lock (priv->part_lock); 1194 1254 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 1195 1260 if (priv->cached_content_type) 1196 1261 g_free (priv->cached_content_type); 1197 1262 priv->cached_content_type = NULL; 1263 1198 1264 g_mutex_unlock (priv->part_lock); 1199 1265 … … 1208 1274 1209 1275 g_mutex_lock (priv->part_lock); 1276 1277 if (priv->cached_filename) 1278 g_free (priv->cached_filename); 1279 priv->cached_filename = NULL; 1280 1210 1281 if (priv->cached_content_type) 1211 1282 g_free (priv->cached_content_type); 1212 1283 priv->cached_content_type = NULL; 1284 1213 1285 if (priv->part && CAMEL_IS_OBJECT (priv->part)) 1214 1286 camel_object_unref (CAMEL_OBJECT (priv->part)); … … 1351 1423 priv->part_lock = g_mutex_new (); 1352 1424 1425 priv->cached_filename = NULL; 1426 priv->cached_content_type = NULL; 1427 1353 1428 return; 1354 1429 } trunk/libtinymailui-gtk/tny-gtk-msg-view.c
r3436 r3448 455 455 } else if (tny_mime_part_content_type_is (part, "image/*")) 456 456 { 457 gboolean nf = FALSE; 457 458 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 459 461 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 } 462 470 gtk_expander_set_label (GTK_EXPANDER (retval), desc); 471 if (nf) 472 g_free (desc); 463 473 } else if (tny_mime_part_content_type_is (part, "multipart/*")) 464 474 {
