diff options
author | NotZed <NotZed@HelixCode.com> | 2000-02-29 07:26:13 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-02-29 07:26:13 +0800 |
commit | f81ae069e4ef8a49f826c458c7b80996cec2036a (patch) | |
tree | 62dd47440cc05997689aee763d7fcc7abfc8c778 | |
parent | bbbee6ba116f1df65514776657e86bc6182a0f56 (diff) | |
download | gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar.gz gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar.bz2 gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar.lz gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar.xz gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.tar.zst gsoc2013-evolution-f81ae069e4ef8a49f826c458c7b80996cec2036a.zip |
Fix a bunch of serious small bugs.
2000-02-28 NotZed <NotZed@HelixCode.com>
* camel-mime-part.c (_parse_header_pair): Dont free this either.
* camel-medium.c (_remove_header): Ugh, dont free the header
before we actually remove it.
(_add_header): Ugh, dont free hashtable entries which may be
duplicated (hash_insert _will_ reference that memory).
* string-utils.c (string_trim): Trimming a 0-length string is not
an error.
* camel-mime-message.c (_parse_header_pair): Fixed very broken
memory handling of header_name/value.
* providers/mbox/camel-mbox-utils.c (camel_mbox_write_xev):
Initialise end_of_last_message always.
(camel_mbox_copy_file_chunk): Stop trying to read if we run out of
data, rather than looping forever.
* providers/mbox/camel-mbox-folder.c (_init): Set search cap on.
(_open): Call parent class to perform open. Remove folder-open
check to parent instead.
(_create): open takes a creation mask, dont use umask to try and
set the open mode.
(_delete): Dont bother checking folder==NULL, its already been
checked on the external interface (changed to an assertion, this
would have to be a camel bug).
(_delete_messages): Likewise.
(_create): Ditto.
(_init): Dont go and clear all the paths and shit that the parent
open just setup for us.
(_delete_messages): Get rid of more umask stuff.
(_append_message): Make sure we pass file mode to open with create.
(_append_message): Cleaned up some indenting to make it readable.
svn path=/trunk/; revision=1985
-rw-r--r-- | camel/ChangeLog | 30 | ||||
-rw-r--r-- | camel/camel-medium.c | 11 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 4 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 1 | ||||
-rw-r--r-- | camel/gmime-utils.c | 8 | ||||
-rw-r--r-- | camel/providers/mbox/camel-mbox-folder.c | 98 | ||||
-rw-r--r-- | camel/providers/mbox/camel-mbox-utils.c | 6 | ||||
-rw-r--r-- | camel/string-utils.c | 3 |
8 files changed, 74 insertions, 87 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 37c2dbda96..7a1e304924 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,23 @@ 2000-02-28 NotZed <NotZed@HelixCode.com> + * camel-mime-part.c (_parse_header_pair): Dont free this either. + + * camel-medium.c (_remove_header): Ugh, dont free the header + before we actually remove it. + (_add_header): Ugh, dont free hashtable entries which may be + duplicated (hash_insert _will_ reference that memory). + + * string-utils.c (string_trim): Trimming a 0-length string is not + an error. + + * camel-mime-message.c (_parse_header_pair): Fixed very broken + memory handling of header_name/value. + + * providers/mbox/camel-mbox-utils.c (camel_mbox_write_xev): + Initialise end_of_last_message always. + (camel_mbox_copy_file_chunk): Stop trying to read if we run out of + data, rather than looping forever. + * camel-folder.c (camel_folder_search_by_expression): No, its not a fatal error to search on a non-searchable folder, you just dont get any matches. @@ -9,6 +27,18 @@ * providers/mbox/camel-mbox-folder.c (_init): Set search cap on. (_open): Call parent class to perform open. Remove folder-open check to parent instead. + (_create): open takes a creation mask, dont use umask to try and + set the open mode. + (_delete): Dont bother checking folder==NULL, its already been + checked on the external interface (changed to an assertion, this + would have to be a camel bug). + (_delete_messages): Likewise. + (_create): Ditto. + (_init): Dont go and clear all the paths and shit that the parent + open just setup for us. + (_delete_messages): Get rid of more umask stuff. + (_append_message): Make sure we pass file mode to open with create. + (_append_message): Cleaned up some indenting to make it readable. * camel-stream-b64.c (my_read_encode): Fixed a typo. diff --git a/camel/camel-medium.c b/camel/camel-medium.c index 1410545c5e..e66e32e543 100644 --- a/camel/camel-medium.c +++ b/camel/camel-medium.c @@ -150,11 +150,15 @@ _add_header (CamelMedium *medium, gchar *header_name, gchar *header_value) header_exists = g_hash_table_lookup_extended (medium->headers, header_name, (gpointer *) &old_header_name, (gpointer *) &old_header_value); + /* ghashtables actually dont duplicate key pointers on existing fields, + just remove the old one first always (avoiding this assumption) */ if (header_exists) { + g_hash_table_remove (medium->headers, old_header_name); +#if 1 g_free (old_header_name); g_free (old_header_value); +#endif } - g_hash_table_insert (medium->headers, g_strdup (header_name), g_strdup (header_value)); } @@ -182,12 +186,11 @@ _remove_header (CamelMedium *medium, const gchar *header_name) (gpointer *) &old_header_name, (gpointer *) &old_header_value); if (header_exists) { + g_hash_table_remove (medium->headers, header_name); + g_free (old_header_name); g_free (old_header_value); } - - g_hash_table_remove (medium->headers, header_name); - } void diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 8fe1764f96..a00d74a938 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -681,7 +681,6 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_ header_value ); _set_recipient_list_from_string (message, "To", header_value); - g_free (header_value); header_handled = TRUE; break; @@ -691,7 +690,6 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_ header_value ); _set_recipient_list_from_string (message, "Cc", header_value); - g_free (header_value); header_handled = TRUE; break; @@ -701,14 +699,12 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_ header_value ); _set_recipient_list_from_string (message, "Bcc", header_value); - g_free (header_value); header_handled = TRUE; break; } if (header_handled) { - g_free (header_name); return TRUE; } else return parent_class->parse_header_pair (mime_part, header_name, header_value); diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index bfd511ca13..b02bbe8713 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -806,7 +806,6 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_ if (header_handled) { - g_free (header_name); return TRUE; } else return FALSE; diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c index 7ceb0219ec..d903eb8a71 100644 --- a/camel/gmime-utils.c +++ b/camel/gmime-utils.c @@ -130,6 +130,13 @@ _store_header_pair_from_string (GArray *header_array, gchar *header_line) if (header_line) { + char *p = strchr(header_line, ':'); + if (p) { + header.name = g_strndup(header_line, p-header_line); + header.value = g_strdup(p+1); + g_array_append_val (header_array, header); + } +#if 0 dich_result = string_dichotomy ( header_line, ':', &header_name, &header_value, STRING_DICHOTOMY_NONE); @@ -152,6 +159,7 @@ _store_header_pair_from_string (GArray *header_array, gchar *header_line) header.value = header_value; g_array_append_val (header_array, header); } +#endif } CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Leaving\n"); diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c index 809c0cda42..d188cf778e 100644 --- a/camel/providers/mbox/camel-mbox-folder.c +++ b/camel/providers/mbox/camel-mbox-folder.c @@ -199,15 +199,6 @@ _init (CamelFolder *folder, CamelStore *parent_store, folder->has_search_capability = TRUE; folder->summary = camel_folder_summary_new (); -#if 0 - mbox_folder->folder_file_path = NULL; - mbox_folder->summary_file_path = NULL; - mbox_folder->folder_dir_path = NULL; - mbox_folder->index_file_path = NULL; - mbox_folder->internal_summary = NULL; - mbox_folder->uid_array = NULL; -#endif - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::init_with_store\n"); } @@ -393,19 +384,11 @@ _exists (CamelFolder *folder, CamelException *ex) gint stat_error; gboolean exists; + g_assert(folder != NULL); + CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxFolder::exists\n"); - - - /* check if the folder object exists */ - if (!folder) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NULL, - "folder object is NULL"); - return FALSE; - } mbox_folder = CAMEL_MBOX_FOLDER(folder); - /* check if the mbox file path is determined */ if (!mbox_folder->folder_file_path) { @@ -482,14 +465,7 @@ _create (CamelFolder *folder, CamelException *ex) int creat_fd; mode_t old_umask; - /* check if the folder object exists */ - if (!folder) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NULL, - "folder object is NULL"); - return FALSE; - } - + g_assert(folder != NULL); /* call default implementation */ parent_class->create (folder, ex); @@ -520,11 +496,9 @@ _create (CamelFolder *folder, CamelException *ex) /* create the mbox file */ /* it must be rw for the user and none for the others */ - old_umask = umask (0700); creat_fd = open (folder_file_path, O_WRONLY | O_CREAT | O_APPEND, - S_IRUSR | S_IWUSR); - umask (old_umask); + S_IRUSR | S_IWUSR, 0600); if (creat_fd == -1) goto io_error; close (creat_fd); @@ -573,14 +547,9 @@ _delete (CamelFolder *folder, gboolean recurse, CamelException *ex) gint unlink_error = 0; gboolean folder_already_exists; - /* check if the folder object exists */ - if (!folder) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NULL, - "folder object is NULL"); - return FALSE; - } + g_assert(folder != NULL); + /* check if the folder object exists */ /* in the case where the folder does not exist, return immediatly */ @@ -679,16 +648,9 @@ _delete_messages (CamelFolder *folder, CamelException *ex) gboolean folder_already_exists; int creat_fd; mode_t old_umask; - - - /* check if the folder object exists */ - if (!folder) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NULL, - "folder object is NULL"); - return FALSE; - } + g_assert(folder!=NULL); + /* in the case where the folder does not exist, return immediatly */ folder_already_exists = camel_folder_exists (folder, ex); @@ -711,11 +673,9 @@ _delete_messages (CamelFolder *folder, CamelException *ex) /* create the mbox file */ /* it must be rw for the user and none for the others */ - old_umask = umask (0700); creat_fd = open (folder_file_path, O_WRONLY | O_TRUNC, - S_IRUSR | S_IWUSR); - umask (old_umask); + S_IRUSR | S_IWUSR, 0600); if (creat_fd == -1) goto io_error; close (creat_fd); @@ -910,7 +870,6 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException gchar *tmp_message_filename; gint fd1, fd2; - CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxFolder::append_message\n"); tmp_message_filename = g_strdup_printf ("%s.tmp", mbox_folder->folder_file_path); @@ -936,15 +895,10 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException */ next_uid = mbox_folder->internal_summary->next_uid; tmp_file_fd = open (tmp_message_filename, O_RDONLY); - message_info_array = camel_mbox_parse_file (tmp_file_fd, - "From - ", - 0, - &tmp_file_size, - &next_uid, - TRUE, - NULL, - 0, - ex); + message_info_array = + camel_mbox_parse_file (tmp_file_fd, "From - ", 0, + &tmp_file_size, &next_uid, TRUE, + NULL, 0, ex); close (tmp_file_fd); @@ -963,14 +917,11 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException if (camel_exception_get_id (ex)) { /* ** FIXME : free the preparsed information */ return; - } + } mbox_summary_info = parsed_information_to_mbox_summary (message_info_array); - - - /* store the number of messages as well as the summary array */ mbox_folder->internal_summary->nb_message += 1; mbox_folder->internal_summary->next_uid = next_uid; @@ -993,18 +944,18 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException fd1 = open (tmp_message_filename, O_RDONLY); fd2 = open (mbox_folder->folder_file_path, O_WRONLY | O_CREAT | O_APPEND, - S_IRUSR | S_IWUSR); + S_IRUSR | S_IWUSR, 0600); if (fd2 == -1) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "could not open the mbox folder file for appending the message\n" - "\t%s\n" - "Full error is : %s\n", - mbox_folder->folder_file_path, - strerror (errno)); - return; - } + camel_exception_setv (ex, + CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, + "could not open the mbox folder file for appending the message\n" + "\t%s\n" + "Full error is : %s\n", + mbox_folder->folder_file_path, + strerror (errno)); + return; + } camel_mbox_copy_file_chunk (fd1, fd2, @@ -1019,7 +970,6 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException /* generate the folder md5 signature */ md5_get_digest_from_file (mbox_folder->folder_file_path, mbox_folder->internal_summary->md5_digest); - g_free (tmp_message_filename); CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::append_message\n"); } diff --git a/camel/providers/mbox/camel-mbox-utils.c b/camel/providers/mbox/camel-mbox-utils.c index 6a49bb869f..3d45daa05f 100644 --- a/camel/providers/mbox/camel-mbox-utils.c +++ b/camel/providers/mbox/camel-mbox-utils.c @@ -168,10 +168,10 @@ camel_mbox_copy_file_chunk (gint fd_src, { gchar buffer [1000]; glong nb_to_read; - glong nb_read, v; + glong nb_read=1, v; nb_to_read = nb_bytes; - while (nb_to_read > 0) { + while (nb_to_read > 0 && nb_read>0) { do { nb_read = read (fd_src, buffer, MIN (1000, nb_to_read)); @@ -223,7 +223,7 @@ camel_mbox_write_xev (gchar *mbox_file_name, guint bytes_to_copy = 0; glong cur_pos = 0; glong cur_offset = 0; - glong end_of_last_message; + glong end_of_last_message = 0; glong next_free_uid; gchar xev_header[20] = "X-Evolution:XXXX-X\n"; gchar *tmp_file_name; diff --git a/camel/string-utils.c b/camel/string-utils.c index 757a907190..1f6d156d03 100644 --- a/camel/string-utils.c +++ b/camel/string-utils.c @@ -228,7 +228,8 @@ string_trim (gchar *string, const gchar *trim_chars, StringTrimOption options) g_return_if_fail (string); length = strlen (string); - g_return_if_fail (length > 0); + if (length==0) + return; first_ok = 0; last_ok = length - 1; |