diff options
author | Srinivasa Ragavan <sragavan@src.gnome.org> | 2007-07-07 03:54:19 +0800 |
---|---|---|
committer | Srinivasa Ragavan <sragavan@src.gnome.org> | 2007-07-07 03:54:19 +0800 |
commit | 2f301d1096f8ed4d869a1d6f2160663307d7605f (patch) | |
tree | 7b0e2fb2a44354424df257ceefed24f889262bbc /mail/em-format-html.c | |
parent | 2b89fd32201b191254e589cf405fe986dc7cd59f (diff) | |
download | gsoc2013-evolution-2f301d1096f8ed4d869a1d6f2160663307d7605f.tar.gz gsoc2013-evolution-2f301d1096f8ed4d869a1d6f2160663307d7605f.tar.zst gsoc2013-evolution-2f301d1096f8ed4d869a1d6f2160663307d7605f.zip |
** Fix for bug #312370 from B S Srinidhi
svn path=/trunk/; revision=33764
Diffstat (limited to 'mail/em-format-html.c')
-rw-r--r-- | mail/em-format-html.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 4a4b51a10c..80392ebc6b 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -449,8 +449,11 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) { CamelStream *cistream = NULL, *costream = NULL, *instream = NULL; CamelURL *url; - ssize_t n, total = 0; + CamelContentType *content_type; + CamelHttpStream *tmp_stream; + ssize_t n, total = 0, pc_complete = 0, nread = 0; char buffer[1500]; + const char *length; if (cancelled || (url = camel_url_new(job->u.uri, NULL)) == NULL) @@ -481,6 +484,13 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) camel_http_stream_set_proxy((CamelHttpStream *)instream, proxy); g_free(proxy); camel_operation_start(NULL, _("Retrieving `%s'"), job->u.uri); + tmp_stream = (CamelHttpStream *)instream; + content_type = camel_http_stream_get_content_type(tmp_stream); + length = camel_header_raw_find(&tmp_stream->headers, "Content-Length", NULL); + d(printf(" Content-Length: %s\n", length)); + if (length != NULL) + total = atoi(length); + camel_content_type_unref(content_type); } else camel_operation_start_transient(NULL, _("Retrieving `%s'"), job->u.uri); @@ -496,8 +506,12 @@ static void emfh_gethttp(struct _EMFormatHTMLJob *job, int cancelled) /* FIXME: progress reporting in percentage, can we get the length always? do we care? */ n = camel_stream_read(instream, buffer, sizeof (buffer)); if (n > 0) { - camel_operation_progress_count(NULL, total); - total += n; + nread += n; + /* If we didn't get a valid Content-Length header, do not try to calculate percentage */ + if (total != 0) { + pc_complete = ((nread * 100) / total); + camel_operation_progress(NULL, pc_complete); + } d(printf(" read %d bytes\n", n)); if (costream && camel_stream_write(costream, buffer, n) == -1) { camel_data_cache_remove(emfh_http_cache, EMFH_HTTP_CACHE_PATH, job->u.uri, NULL); |