Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Revert "wip: fix leakage"

This reverts commit 2e1f3e5.
  • Loading branch information...
commit 88052e1d317a23bccb0ee365cec4a0e4bf52f6ad 1 parent 4853078
Paul J Stevens authored April 23, 2012
60  src/dbmail-message.c
@@ -724,7 +724,6 @@ DbmailMessage * dbmail_message_init_with_string(DbmailMessage *self, const GStri
724 724
 	GMimeStream *stream;
725 725
 
726 726
 	assert(self->content == NULL);
727  
-	assert(self->raw_content == NULL);
728 727
 
729 728
 	stream = g_mime_stream_mem_new_with_buffer(str->str, str->len);
730 729
 	g_mime_stream_mem_set_owner(stream, TRUE);
@@ -732,34 +731,36 @@ DbmailMessage * dbmail_message_init_with_string(DbmailMessage *self, const GStri
732 731
 	parser = g_mime_parser_new_with_stream(stream);
733 732
 	g_object_unref(stream);
734 733
 
  734
+	if (strncmp(str->str, "From ", 5) == 0) {
  735
+		/* don't use gmime's from scanner since body lines may begin with 'From ' */
  736
+		char *end;
  737
+		if ((end = g_strstr_len(str->str, 80, "\n"))) {
  738
+			size_t l = end - str->str;
  739
+			from = g_strndup(str->str, l);
  740
+			TRACE(TRACE_DEBUG, "From_ [%s]", from);
  741
+		}
  742
+	}
  743
+
735 744
 	content = GMIME_OBJECT(g_mime_parser_construct_message(parser));
736 745
 	if (content) {
737 746
 		dbmail_message_set_class(self, DBMAIL_MESSAGE);
738  
-
739  
-		if (strncmp(str->str, "From ", 5) == 0) {
740  
-			/* don't use gmime's from scanner since body lines may begin with 'From ' */
741  
-			char *end;
742  
-			if ((end = g_strstr_len(str->str, 80, "\n"))) {
743  
-				size_t l = end - str->str;
744  
-				from = g_strndup(str->str, l);
745  
-				TRACE(TRACE_DEBUG, "From_ [%s]", from);
746  
-				dbmail_message_set_internal_date(self, from);
747  
-				g_free(from);
748  
-			}
749  
-		}
750  
-
751 747
 		self->content = content;
752  
-		self->raw_content = g_strdup(str->str);
  748
+		self->raw_content = dbmail_message_to_string(self);
  749
+		if (from) {
  750
+			dbmail_message_set_internal_date(self, from);
  751
+		}
  752
+		g_object_unref(parser);
753 753
 	} else {
754 754
 		content = GMIME_OBJECT(g_mime_parser_construct_part(parser));
755 755
 		if (content) {
756 756
 			dbmail_message_set_class(self, DBMAIL_MESSAGE_PART);
757 757
 			self->content = content;
758  
-			self->raw_content = g_strdup(str->str);
  758
+			self->raw_content = dbmail_message_to_string(self);
  759
+			g_object_unref(parser);
759 760
 		}
760 761
 	}
761  
-	g_object_unref(parser);
762 762
 
  763
+	if (from) g_free(from);
763 764
 	_map_headers(self);
764 765
 	return self;
765 766
 }
@@ -816,14 +817,15 @@ static void _register_header(const char *header, const char *value, gpointer use
816 817
 		g_relation_insert(m->headers, hname, hvalue);
817 818
 }
818 819
 
819  
-void dbmail_message_set_physid(DbmailMessage *self, uint64_t id)
  820
+void dbmail_message_set_physid(DbmailMessage *self, uint64_t physid)
820 821
 {
821  
-	self->id = id;
  822
+	self->id = physid;
  823
+	self->physid = physid;
822 824
 }
823 825
 
824 826
 uint64_t dbmail_message_get_physid(const DbmailMessage *self)
825 827
 {
826  
-	return self->id;
  828
+	return self->physid;
827 829
 }
828 830
 
829 831
 void dbmail_message_set_internal_date(DbmailMessage *self, char *internal_date)
@@ -1121,7 +1123,7 @@ static int _update_message(DbmailMessage *self)
1121 1123
 	uint64_t rfcsize = (uint64_t)dbmail_message_get_size(self,TRUE);
1122 1124
 
1123 1125
 	if (! db_update("UPDATE %sphysmessage SET messagesize = %lu, rfcsize = %lu WHERE id = %lu", 
1124  
-			DBPFX, size, rfcsize, self->id))
  1126
+			DBPFX, size, rfcsize, self->physid))
1125 1127
 		return DM_EQUERY;
1126 1128
 
1127 1129
 	if (! db_update("UPDATE %smessages SET status = %d WHERE message_idnr = %lu", 
@@ -1336,7 +1338,7 @@ void _message_cache_envelope_date(const DbmailMessage *self)
1336 1338
 	_header_value_get_id(value, sortfield, datefield, &headervalue_id);
1337 1339
 
1338 1340
 	if (headervalue_id && headername_id)
1339  
-		_header_insert(self->id, headername_id, headervalue_id);
  1341
+		_header_insert(self->physid, headername_id, headervalue_id);
1340 1342
 
1341 1343
 	g_free(value);
1342 1344
 	g_free(sortfield);
@@ -1346,7 +1348,7 @@ void _message_cache_envelope_date(const DbmailMessage *self)
1346 1348
 int dbmail_message_cache_headers(const DbmailMessage *self)
1347 1349
 {
1348 1350
 	assert(self);
1349  
-	assert(self->id);
  1351
+	assert(self->physid);
1350 1352
 
1351 1353
 	if (! GMIME_IS_MESSAGE(self->content)) {
1352 1354
 		TRACE(TRACE_ERR,"self->content is not a message");
@@ -1731,7 +1733,7 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint
1731 1733
 
1732 1734
 		/* Insert relation between physmessage, header name and header value */
1733 1735
 		if (headervalue_id)
1734  
-			_header_insert(self->id, headername_id, headervalue_id);
  1736
+			_header_insert(self->physid, headername_id, headervalue_id);
1735 1737
 		else
1736 1738
 			TRACE(TRACE_INFO, "error inserting headervalue. skipping.");
1737 1739
 
@@ -1747,7 +1749,7 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint
1747 1749
 	return FALSE;
1748 1750
 }
1749 1751
 
1750  
-static void insert_field_cache(uint64_t id, const char *field, const char *value)
  1752
+static void insert_field_cache(uint64_t physid, const char *field, const char *value)
1751 1753
 {
1752 1754
 	gchar *clean_value;
1753 1755
 	C c; S s;
@@ -1761,7 +1763,7 @@ static void insert_field_cache(uint64_t id, const char *field, const char *value
1761 1763
 	TRY
1762 1764
 		db_begin_transaction(c);
1763 1765
 		s = db_stmt_prepare(c,"INSERT INTO %s%sfield (physmessage_id, %sfield) VALUES (?,?)", DBPFX, field, field);
1764  
-		db_stmt_set_u64(s, 1, id);
  1766
+		db_stmt_set_u64(s, 1, physid);
1765 1767
 		db_stmt_set_str(s, 2, clean_value);
1766 1768
 		db_stmt_exec(s);
1767 1769
 		db_commit_transaction(c);
@@ -1796,7 +1798,7 @@ void dbmail_message_cache_referencesfield(const DbmailMessage *self)
1796 1798
 	g_free(field);
1797 1799
 
1798 1800
 	if (! refs) {
1799  
-		TRACE(TRACE_DEBUG, "reference_decode failed [%lu]", self->id);
  1801
+		TRACE(TRACE_DEBUG, "reference_decode failed [%lu]", self->physid);
1800 1802
 		return;
1801 1803
 	}
1802 1804
 	
@@ -1805,7 +1807,7 @@ void dbmail_message_cache_referencesfield(const DbmailMessage *self)
1805 1807
 	
1806 1808
 	while (refs->msgid) {
1807 1809
 		if (! g_tree_lookup(tree,refs->msgid)) {
1808  
-			insert_field_cache(self->id, "references", refs->msgid);
  1810
+			insert_field_cache(self->physid, "references", refs->msgid);
1809 1811
 			g_tree_insert(tree,refs->msgid,refs->msgid);
1810 1812
 		}
1811 1813
 		if (refs->next == NULL)
@@ -1828,7 +1830,7 @@ void dbmail_message_cache_envelope(const DbmailMessage *self)
1828 1830
 	TRY
1829 1831
 		db_begin_transaction(c);
1830 1832
 		s = db_stmt_prepare(c, "INSERT INTO %senvelope (physmessage_id, envelope) VALUES (?,?)", DBPFX);
1831  
-		db_stmt_set_u64(s, 1, self->id);
  1833
+		db_stmt_set_u64(s, 1, self->physid);
1832 1834
 		db_stmt_set_str(s, 2, envelope);
1833 1835
 		db_stmt_exec(s);
1834 1836
 		db_commit_transaction(c);
1  src/dbmailtypes.h
@@ -131,6 +131,7 @@ enum DBMAIL_MESSAGE_FILTER_TYPES {
131 131
 
132 132
 typedef struct {
133 133
 	uint64_t id;
  134
+	uint64_t physid;
134 135
 	time_t internal_date;
135 136
 	int internal_date_gmtoff;
136 137
 	GString *envelope_recipient;

0 notes on commit 88052e1

Please sign in to comment.
Something went wrong with that request. Please try again.