summaryrefslogtreecommitdiffstats
path: root/testing/dbmail/post-rc3.patch
blob: 9d7e34be36dba369d840b24d80477d4bdd17804a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
From b73172be67b4665b04c791f914cf284e01dea33c Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Mon, 15 Aug 2011 16:11:32 +0200
Subject: [PATCH 1/8] fix broken SEARCH TEXT (#912)'

---
 src/dbmail-mailbox.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/dbmail-mailbox.c b/src/dbmail-mailbox.c
index 3491105..09be275 100644
--- a/src/dbmail-mailbox.c
+++ b/src/dbmail-mailbox.c
@@ -1183,7 +1183,7 @@ static GTree * mailbox_search(DbmailMailbox *self, search_key_t *s)
 
 			case IST_DATA_TEXT:
 
-			g_string_printf(q,"SELECT DISTINCT m.message_idnr"
+			g_string_printf(q,"SELECT DISTINCT m.message_idnr "
 					"FROM %smimeparts k "
 					"LEFT JOIN %spartlists l ON k.id=l.part_id "
 					"LEFT JOIN %sphysmessage p ON l.physmessage_id=p.id "
-- 
1.7.7.1

From cd5cc297ab1c05103c45f6ee903298eca5357a19 Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Sat, 20 Aug 2011 14:00:35 +0200
Subject: [PATCH 2/8] fix dbmail.h generation (#916)

---
 acinclude.m4    |    2 +-
 configure       |    2 +-
 src/dbmail.h.in |    4 +---
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 2d2960d..fbf702a 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -300,7 +300,7 @@ AC_DEFUN([DM_CHECK_ZDB], [dnl
 ])
 
 AC_DEFUN([DM_SET_SQLITECREATE], [dnl
-	SQLITECREATE=`sed -e 's/\"/\\\"/g' -e 's/^/\"/' -e 's/$/\\\n\" \\\\/'  sql/sqlite/create_tables.sqlite`
+	SQLITECREATE=`sed -e 's/\"/\\\"/g' -e 's/^/\"/' -e 's/$/\\\n\"/' -e '$!s/$/ \\\\/'  sql/sqlite/create_tables.sqlite`
 ])
 
 AC_DEFUN([DM_CHECK_MATH], [dnl
diff --git a/configure b/configure
index 6be85f6..e9d6e84 100755
--- a/configure
+++ b/configure
@@ -6697,7 +6697,7 @@ if test "x$ac_cv_lib_crypt_crypt" = x""yes; then :
 fi
 
 
-	SQLITECREATE=`sed -e 's/\"/\\\"/g' -e 's/^/\"/' -e 's/$/\\\n\" \\\\/'  sql/sqlite/create_tables.sqlite`
+	SQLITECREATE=`sed -e 's/\"/\\\"/g' -e 's/^/\"/' -e 's/$/\\\n\"/' -e '$!s/$/ \\\\/'  sql/sqlite/create_tables.sqlite`
 
 
 
diff --git a/src/dbmail.h.in b/src/dbmail.h.in
index 956246a..15acc31 100644
--- a/src/dbmail.h.in
+++ b/src/dbmail.h.in
@@ -183,9 +183,7 @@
 ""
 
 /* include sql/sqlite/create_tables.sqlite for autocreation */
-#define DM_SQLITECREATE \
-@SQLITECREATE@
-""
+#define DM_SQLITECREATE @SQLITECREATE@
 
 /** default directory and extension for pidfiles */
 #define DEFAULT_PID_DIR "@DM_STATEDIR@"
-- 
1.7.7.1

From 0e640aa861ceebebff59877440d084fa2dcd9efd Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Thu, 22 Sep 2011 16:39:53 +0200
Subject: [PATCH 3/8] fix IDLE regression (#927)

---
 src/imapcommands.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/imapcommands.c b/src/imapcommands.c
index 7bfe3c1..8159214 100644
--- a/src/imapcommands.c
+++ b/src/imapcommands.c
@@ -1113,6 +1113,7 @@ int _ic_idle(ImapSession *self)
 	int idle_timeout = IDLE_TIMEOUT;
 	field_t val;
 
+	ci_cork(self->ci);
 	GETCONFIGVALUE("idle_timeout", "IMAP", val);
 	if ( strlen(val) && (idle_timeout = atoi(val)) <= 0 ) {
 		TRACE(TRACE_ERR, "[%p] illegal value for idle_timeout [%s]", self, val);
@@ -1125,6 +1126,7 @@ int _ic_idle(ImapSession *self)
 	dbmail_imap_session_buff_printf(self, "+ idling\r\n");
 	dbmail_imap_session_mailbox_status(self,TRUE);
 	dbmail_imap_session_buff_flush(self);
+	ci_uncork(self->ci);
 
 	return 0;
 }
-- 
1.7.7.1

From a82434e61e10f7e3e6b5feefb12c341ad96229ea Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Fri, 21 Oct 2011 15:57:31 +0200
Subject: [PATCH 4/8] handle hangups better during read (#932)

---
 src/imap4.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/imap4.c b/src/imap4.c
index 5fbf849..1d6869a 100644
--- a/src/imap4.c
+++ b/src/imap4.c
@@ -143,20 +143,23 @@ void imap_cb_read(void *arg)
 {
 	ImapSession *session = (ImapSession *) arg;
 
-	TRACE(TRACE_DEBUG,"reading...");
-
 	ci_read_cb(session->ci);
 
 	size_t have = session->ci->read_buffer->len;
+	size_t need = session->ci->rbuff_size;
+
+	int enough = (need>0?(have == 0):(have > 0));
+
 	int state = session->ci->client_state;
 
+	TRACE(TRACE_DEBUG,"reading %d: %ld/%ld", enough, have, need);
 	if (state & CLIENT_ERR) {
 		ci_cork(session->ci);
 		dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
 		return;
 	} 
 	if (state & CLIENT_EOF) {
-		if (have)
+		if (enough)
 			imap_handle_input(session);
 		else
 			imap_session_bailout(session);
-- 
1.7.7.1

From f9f332c7b917c6b0683b0d43a0f614d675181855 Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Sat, 22 Oct 2011 13:53:12 +0200
Subject: [PATCH 5/8] gracefully degrade after decoding error (#930)

---
 src/dbmail-message.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/dbmail-message.c b/src/dbmail-message.c
index e62cfb4..cf8fc23 100644
--- a/src/dbmail-message.c
+++ b/src/dbmail-message.c
@@ -1457,12 +1457,11 @@ static int _header_value_get_id(const char *value, const char *sortfield, const
 	CATCH(SQLException)
 		LOG_SQLERROR;
 		db_rollback_transaction(c);
+		*id = 0;
 	FINALLY
 		db_con_close(c);
 	END_TRY;
 
-	assert(*id);
-
 	g_free(hash);
 
 	return TRUE;
@@ -1596,7 +1595,10 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint
 		g_free(value);
 
 		/* Insert relation between physmessage, header name and header value */
-		_header_insert(self->physid, headername_id, headervalue_id);
+		if (headervalue_id)
+			_header_insert(self->physid, headername_id, headervalue_id);
+		else
+			TRACE(TRACE_INFO, "error inserting headervalue. skipping.");
 
 		headervalue_id=0;
 
-- 
1.7.7.1

From 11bcc6294807be46ded604b23cad2648fcbf7c5b Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Sat, 22 Oct 2011 18:08:59 +0200
Subject: [PATCH 6/8] reset timeout after idle is done (#932)

---
 src/imap4.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/imap4.c b/src/imap4.c
index 1d6869a..69a7a7e 100644
--- a/src/imap4.c
+++ b/src/imap4.c
@@ -468,6 +468,7 @@ void dbmail_imap_session_reset(ImapSession *session)
 	session->parser_state = FALSE;
 	dbmail_imap_session_args_free(session, FALSE);
 
+	session->ci->timeout->tv_sec = server_conf->timeout; 
 	ci_uncork(session->ci);
 	
 	return;
-- 
1.7.7.1

From 8dc7ab5ec45a4321af191fecd7da1f50d76d3ce1 Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Mon, 24 Oct 2011 16:23:59 +0200
Subject: [PATCH 7/8] call database schema version check on all connections

---
 src/dm_db.c |   17 ++++++++++++-----
 src/main.c  |    5 -----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/dm_db.c b/src/dm_db.c
index 22cfe95..ec516e8 100644
--- a/src/dm_db.c
+++ b/src/dm_db.c
@@ -216,7 +216,7 @@ int db_connect(void)
 	db_connected = 3;
 	db_con_close(c);
 
-	return 0;
+	return db_check_version();
 }
 
 /* But sometimes this gets called after help text or an
@@ -803,19 +803,26 @@ static void check_table_exists(C c, const char *table, const char *errormessage)
 int db_check_version(void)
 {
 	C c = db_con_get();
+	volatile int ok = 0;
 	TRY
 		check_table_exists(c, "physmessage", "pre-2.0 database incompatible. You need to run the conversion script");
 		check_table_exists(c, "headervalue", "2.0 database incompatible. You need to add the header tables.");
-		check_table_exists(c, "envelope", "2.1 database incompatible. You need to add the envelopes table and run dbmail-util -by");
-		check_table_exists(c, "mimeparts", "2.3 database incompatible.");
-		check_table_exists(c, "header", "2.3.5 database incompatible - single instance header storage missing.");
+		check_table_exists(c, "envelope", "2.1+ database incompatible. You need to add the envelopes table and run dbmail-util -by");
+		check_table_exists(c, "mimeparts", "3.x database incompatible.");
+		check_table_exists(c, "header", "3.x database incompatible - single instance header storage missing.");
+		ok = 1;
 	CATCH(SQLException)
 		LOG_SQLERROR;
 	FINALLY
 		db_con_close(c);
 	END_TRY;
 
-	return DM_SUCCESS;
+	if (ok)
+		TRACE(TRACE_DEBUG,"Tables OK");
+	else
+		TRACE(TRACE_WARNING,"Schema version incompatible. Bailing out");
+
+	return ok?DM_SUCCESS:DM_EQUERY;
 }
 
 /* test existence of usermap table */
diff --git a/src/main.c b/src/main.c
index f9c8328..4065997 100644
--- a/src/main.c
+++ b/src/main.c
@@ -240,11 +240,6 @@ int main(int argc, char *argv[])
 		goto freeall;
 	}
 	
-        if (db_check_version() != 0) {
-                exitcode = EX_TEMPFAIL;
-                goto freeall;
-        }
-
 	/* read the whole message */
 	memset(buf, 0, sizeof(buf));
 	while ( (n = read(fileno(stdin), (void *)buf, READ_SIZE-1)) > 0) {
-- 
1.7.7.1

From 105cfefa0a1cc7366b66c6759e05e46ae5a6e53c Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Sat, 29 Oct 2011 15:57:09 +0200
Subject: [PATCH 8/8] gmime-2.6 compatibility (#935)

---
 src/dbmail-message.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/dbmail-message.c b/src/dbmail-message.c
index cf8fc23..8a1a66c 100644
--- a/src/dbmail-message.c
+++ b/src/dbmail-message.c
@@ -561,7 +561,7 @@ gboolean store_mime_object(GMimeObject *parent, GMimeObject *object, DbmailMessa
 		// part of the rfc822 headers
 		skiphead = TRUE;
 
-		g_mime_header_list_set_raw (GMIME_MESSAGE(object)->mime_part->headers, NULL);
+		g_mime_header_list_set_stream (GMIME_MESSAGE(object)->mime_part->headers, NULL);
 		mime_part = g_mime_message_get_mime_part((GMimeMessage *)object);
 	} else
 		mime_part = object;
@@ -1744,8 +1744,7 @@ DbmailMessage * dbmail_message_construct(DbmailMessage *self,
 	TRACE(TRACE_DEBUG, "from: [%s] to: [%s] subject: [%s] body: [%s]", from, to, subject, body);
 	g_mime_message_set_sender(message, from);
 	g_mime_message_set_subject(message, subject);
-	g_mime_object_set_header(GMIME_OBJECT(message), "To", to);
-	g_mime_message_add_recipient(message, GMIME_RECIPIENT_TYPE_TO, "", to);
+	g_mime_message_add_recipient(message, GMIME_RECIPIENT_TYPE_TO, NULL, to);
 
 	// construct mime-part
 	mime_part = g_mime_part_new();
-- 
1.7.7.1

From e95bcfa3f470de0f385a88266bf07065e65695a2 Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Wed, 02 Nov 2011 04:30:45 +0000
Subject: re-indent php code

---
diff --git a/contrib/dbmailclient.php b/contrib/dbmailclient.php
index ffe5cd0..0693c0a 100644
--- a/contrib/dbmailclient.php
+++ b/contrib/dbmailclient.php
@@ -190,137 +190,137 @@ class DBMailMessage extends DBMailMailbox
 
 class Curl 
 {
-    public $cookie_file;
-    public $headers = array();
-    public $options = array();
-    public $referer = '';
-    public $user_agent = '';
+	public $cookie_file;
+	public $headers = array();
+	public $options = array();
+	public $referer = '';
+	public $user_agent = '';
 
-    protected $error = '';
-    protected $handle;
+	protected $error = '';
+	protected $handle;
 
 
-    public function __construct() 
-    {
+	public function __construct() 
+	{
 		$this->cookie_file = realpath('.').'/curl_cookie.txt';
-        $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ?
-            $_SERVER['HTTP_USER_AGENT'] :
-            'Curl/PHP ' . PHP_VERSION . ' (http://github.com/shuber/curl/)';
-    }
-
-    public function delete($url, $vars = array()) 
-    {
-        return $this->request('DELETE', $url, $vars);
-    }
-
-    public function error() 
-    {
-        return $this->error;
-    }
-
-    public function get($url, $vars = array()) 
-    {
-        if (!empty($vars)) {
-            $url .= (stripos($url, '?') !== false) ? '&' : '?';
-            $url .= http_build_query($vars, '', '&');
-        }
-        return $this->request('GET', $url);
-    }
-
-    public function post($url, $vars = array()) 
-    {
-        return $this->request('POST', $url, $vars);
-    }
-
-    public function put($url, $vars = array()) 
-    {
-        return $this->request('PUT', $url, $vars);
-    }
-
-    protected function request($method, $url, $vars = array()) 
-    {
-        $this->handle = curl_init();
-        
-        # Set some default CURL options
-        curl_setopt($this->handle, CURLOPT_COOKIEFILE, $this->cookie_file);
-        curl_setopt($this->handle, CURLOPT_COOKIEJAR, $this->cookie_file);
-        curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($this->handle, CURLOPT_HEADER, true);
-        curl_setopt($this->handle, CURLOPT_POSTFIELDS, (is_array($vars) ? http_build_query($vars, '', '&') : $vars));
-        curl_setopt($this->handle, CURLOPT_REFERER, $this->referer);
-        curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($this->handle, CURLOPT_URL, $url);
-        curl_setopt($this->handle, CURLOPT_USERAGENT, $this->user_agent);
-        
-        # Format custom headers for this request and set CURL option
-        $headers = array();
-        foreach ($this->headers as $key => $value) {
-            $headers[] = $key.': '.$value;
-        }
-        curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
-        
-        # Determine the request method and set the correct CURL option
-        switch ($method) {
-            case 'GET':
-                curl_setopt($this->handle, CURLOPT_HTTPGET, true);
-                break;
-            case 'POST':
-                curl_setopt($this->handle, CURLOPT_POST, true);
-                break;
-            default:
-                curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $method);
-        }
-        
-        # Set any custom CURL options
-        foreach ($this->options as $option => $value) {
-            curl_setopt($this->handle, constant('CURLOPT_'.str_replace('CURLOPT_', '', strtoupper($option))), $value);
-        }
-        
-        $response = curl_exec($this->handle);
-        if ($response) {
-            $response = new CurlResponse($response);
-        } else {
-            $this->error = curl_errno($this->handle).' - '.curl_error($this->handle);
-        }
-        curl_close($this->handle);
-        return $response;
-    }
+		$this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ?
+			$_SERVER['HTTP_USER_AGENT'] :
+			'Curl/PHP ' . PHP_VERSION . ' (http://github.com/shuber/curl/)';
+	}
+
+	public function delete($url, $vars = array()) 
+	{
+		return $this->request('DELETE', $url, $vars);
+	}
+
+	public function error() 
+	{
+		return $this->error;
+	}
+
+	public function get($url, $vars = array()) 
+	{
+		if (!empty($vars)) {
+			$url .= (stripos($url, '?') !== false) ? '&' : '?';
+			$url .= http_build_query($vars, '', '&');
+		}
+		return $this->request('GET', $url);
+	}
+
+	public function post($url, $vars = array()) 
+	{
+		return $this->request('POST', $url, $vars);
+	}
+
+	public function put($url, $vars = array()) 
+	{
+		return $this->request('PUT', $url, $vars);
+	}
+
+	protected function request($method, $url, $vars = array()) 
+	{
+		$this->handle = curl_init();
+
+		# Set some default CURL options
+		curl_setopt($this->handle, CURLOPT_COOKIEFILE, $this->cookie_file);
+		curl_setopt($this->handle, CURLOPT_COOKIEJAR, $this->cookie_file);
+		curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, true);
+		curl_setopt($this->handle, CURLOPT_HEADER, true);
+		curl_setopt($this->handle, CURLOPT_POSTFIELDS, (is_array($vars) ? http_build_query($vars, '', '&') : $vars));
+		curl_setopt($this->handle, CURLOPT_REFERER, $this->referer);
+		curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
+		curl_setopt($this->handle, CURLOPT_URL, $url);
+		curl_setopt($this->handle, CURLOPT_USERAGENT, $this->user_agent);
+
+		# Format custom headers for this request and set CURL option
+		$headers = array();
+		foreach ($this->headers as $key => $value) {
+			$headers[] = $key.': '.$value;
+		}
+		curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
+
+		# Determine the request method and set the correct CURL option
+		switch ($method) {
+		case 'GET':
+			curl_setopt($this->handle, CURLOPT_HTTPGET, true);
+			break;
+		case 'POST':
+			curl_setopt($this->handle, CURLOPT_POST, true);
+			break;
+		default:
+			curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $method);
+		}
+
+		# Set any custom CURL options
+		foreach ($this->options as $option => $value) {
+			curl_setopt($this->handle, constant('CURLOPT_'.str_replace('CURLOPT_', '', strtoupper($option))), $value);
+		}
+
+		$response = curl_exec($this->handle);
+		if ($response) {
+			$response = new CurlResponse($response);
+		} else {
+			$this->error = curl_errno($this->handle).' - '.curl_error($this->handle);
+		}
+		curl_close($this->handle);
+		return $response;
+	}
 
 }
 
 class CurlResponse 
 {
-    public $body = '';
-    public $headers = array();
-
-    public function __construct($response) 
-    {
-        # Extract headers from response
-        $pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims';
-        preg_match_all($pattern, $response, $matches);
-        $headers = split("\r\n", str_replace("\r\n\r\n", '', array_pop($matches[0])));
-        
-        # Extract the version and status from the first header
-        $version_and_status = array_shift($headers);
-        preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', $version_and_status, $matches);
-        $this->headers['Http-Version'] = $matches[1];
-        $this->headers['Status-Code'] = $matches[2];
-        $this->headers['Status'] = $matches[2].' '.$matches[3];
-        
-        # Convert headers into an associative array
-        foreach ($headers as $header) {
-            preg_match('#(.*?)\:\s(.*)#', $header, $matches);
-            $this->headers[$matches[1]] = $matches[2];
-        }
-        
-        # Remove the headers from the response body
-        $this->body = preg_replace($pattern, '', $response);
-    }
-
-    public function __toString() 
-    {
-        return $this->body;
-    }
+	public $body = '';
+	public $headers = array();
+
+	public function __construct($response) 
+	{
+		# Extract headers from response
+		$pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims';
+		preg_match_all($pattern, $response, $matches);
+		$headers = split("\r\n", str_replace("\r\n\r\n", '', array_pop($matches[0])));
+
+		# Extract the version and status from the first header
+		$version_and_status = array_shift($headers);
+		preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', $version_and_status, $matches);
+		$this->headers['Http-Version'] = $matches[1];
+		$this->headers['Status-Code'] = $matches[2];
+		$this->headers['Status'] = $matches[2].' '.$matches[3];
+
+		# Convert headers into an associative array
+		foreach ($headers as $header) {
+			preg_match('#(.*?)\:\s(.*)#', $header, $matches);
+			$this->headers[$matches[1]] = $matches[2];
+		}
+
+		# Remove the headers from the response body
+		$this->body = preg_replace($pattern, '', $response);
+	}
+
+	public function __toString() 
+	{
+		return $this->body;
+	}
 }
 
 
--
cgit v0.8.3.4
From 288b73a79fe20bae7737fb622aefff761bb34c3f Mon Sep 17 00:00:00 2001
From: Paul J Stevens <paul@nfg.nl>
Date: Wed, 02 Nov 2011 04:31:12 +0000
Subject: parse From_ time as localtime

---
diff --git a/src/dbmail-mailbox.c b/src/dbmail-mailbox.c
index 09be275..5e493ab 100644
--- a/src/dbmail-mailbox.c
+++ b/src/dbmail-mailbox.c
@@ -100,7 +100,7 @@ static gchar * _message_get_envelope_date(const DbmailMessage *self)
 	
 	res = g_new0(char, TIMESTRING_SIZE+1);
 	memset(&gmt,'\0', sizeof(struct tm));
-	gmtime_r(&self->internal_date, &gmt);
+	localtime_r(&self->internal_date, &gmt);
 
 	strftime(res, TIMESTRING_SIZE, "%a %b %d %H:%M:%S %Y", &gmt);
 	return res;
diff --git a/src/dbmail-message.c b/src/dbmail-message.c
index 8a1a66c..1b4d826 100644
--- a/src/dbmail-message.c
+++ b/src/dbmail-message.c
@@ -837,7 +837,7 @@ gchar * dbmail_message_get_internal_date(const DbmailMessage *self, int thisyear
 	
 	res = g_new0(char, TIMESTRING_SIZE+1);
 	memset(&gmt,'\0', sizeof(struct tm));
-	gmtime_r(&self->internal_date, &gmt);
+	localtime_r(&self->internal_date, &gmt);
 
 	/* override if the date is not sane */
 	if (thisyear && gmt.tm_year + 1900 > thisyear + 1) {
--
cgit v0.8.3.4