This repository has been archived by the owner on May 25, 2024. It is now read-only.
forked from emersonfaria/ExpressoLivre3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageTest.php
1362 lines (1170 loc) · 51.7 KB
/
MessageTest.php
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Tine 2.0 - http://www.tine20.org
*
* @package Felamimail
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Philipp Schüle <p.schuele@metaways.de>
*
*/
/**
* Test helper
*/
require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
/**
* Test class for Tinebase_Group
*/
class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
{
/**
* @var Felamimail_Controller_Message
*/
protected $_controller = NULL;
/**
* @var Felamimail_Model_Account
*/
protected $_account = NULL;
/**
* keep track of created messages
*
* @var Tinebase_Record_RecordSet
*/
protected $_createdMessages;
/**
* @var Felamimail_Backend_Imap
*/
protected $_imap = NULL;
/**
* @var Felamimail_Controller_Cache_Message
*/
protected $_cache;
/**
* @var Felamimail_Model_Folder
*/
protected $_folder = NULL;
/**
* name of the folder to use for tests
* @var string
*/
protected $_testFolderName = 'Junk';
/**
* accounts to delete in tearDown
*
* @var array
*/
protected $_accountsToDelete = array();
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main()
{
$suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Felamimail Message Controller Tests');
PHPUnit_TextUI_TestRunner::run($suite);
}
/**
* Sets up the fixture.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$this->_account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
$this->_controller = Felamimail_Controller_Message::getInstance();
$this->_imap = Felamimail_Backend_ImapFactory::factory($this->_account);
$this->_folder = $this->getFolder($this->_testFolderName);
$this->_imap->selectFolder($this->_testFolderName);
$this->_cache = Felamimail_Controller_Cache_Message::getInstance();
$this->_createdMessages = new Tinebase_Record_RecordSet('Felamimail_Model_Message');
}
/**
* Tears down the fixture
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown()
{
try {
Felamimail_Controller_Message_Flags::getInstance()->addFlags($this->_createdMessages, array(Zend_Mail_Storage::FLAG_DELETED));
} catch (Zend_Mail_Storage_Exception $zmse) {
// do nothing
}
foreach ($this->_accountsToDelete as $account) {
Felamimail_Controller_Account::getInstance()->delete($account);
}
}
/********************************* test funcs *************************************/
/**
* test getting multiple messages
*/
public function testGetMultipleMessages()
{
$message1 = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$message2 = $this->messageTestHelper('text_plain.eml', 'text/plain');
$messages = $this->_controller->getMultiple(array(
$message1->getId(),
$message2->getId()
));
$this->assertEquals(2, count($messages));
}
/**
* test search with cache
* - test text_plain.eml message
* - test from header
*/
public function testSearchWithCache()
{
// get inbox folder id
Felamimail_Controller_Cache_Folder::getInstance()->update($this->_account->getId());
$folderBackend = new Felamimail_Backend_Folder();
$folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account->getId(), $this->_testFolderName);
// clear cache and empty folder
$this->_cache->clear($folder->getId());
Felamimail_Controller_Folder::getInstance()->emptyFolder($folder->getId());
// append message
$this->_appendMessage('text_plain.eml', $this->_folder);
// search messages in test folder
$this->_cache->updateCache($folder);
$result = $this->_controller->search($this->_getFilter($folder->getId()));
//print_r($result->toArray());
// check result
$firstMessage = $result->getFirstRecord();
$this->_createdMessages->addRecord($firstMessage);
$this->assertGreaterThan(0, count($result));
$this->assertEquals($folder->getId(), $firstMessage->folder_id);
$this->assertEquals("Re: [gentoo-dev] `paludis --info' is not like `emerge --info'", $firstMessage->subject);
$this->assertEquals('Pipping, Sebastian (Luxembourg)', $firstMessage->from_name);
$this->assertEquals('webmaster@changchung.org', $firstMessage->from_email);
$this->assertEquals(array('gentoo-dev@lists.gentoo.org', 'webmaster@changchung.org') , $firstMessage->to);
// check cache entries
$cacheBackend = new Felamimail_Backend_Cache_Sql_Message();
$cachedMessage = $cacheBackend->get($firstMessage->getId());
$this->assertEquals($folder->getId(), $cachedMessage->folder_id);
$this->assertEquals(Tinebase_DateTime::now()->format('Y-m-d'), $cachedMessage->timestamp->format('Y-m-d'));
// clear cache
$this->_cache->clear($folder->getId());
}
/**
* testBodyStructureTextPlain
*/
public function testBodyStructureTextPlain()
{
$expectedStructure = array(
'partId' => 1,
'contentType' => 'text/plain',
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'ISO-8859-1'
),
'id' => '',
'description' => '',
'encoding' => '7bit',
'size' => 388,
'disposition' => '',
'language' => '',
'location' => '',
);
$message = $this->messageTestHelper('text_plain.eml', 'text/plain');
$lines = $message['structure']['lines'];
$structure = $message['structure'];
unset($structure['lines']);
$this->assertEquals($expectedStructure, $structure, 'structure does not match');
// dbmail always has one more line than dovecot
$this->assertTrue(in_array($lines, array(17, 18)));
}
/**
* testBodyStructureMultipartAlternative
*/
public function testBodyStructureMultipartAlternative()
{
$expectedStructure = array(
'partId' => null,
'contentType' => 'multipart/alternative',
'type' => 'multipart',
'subType' => 'alternative',
'parts' => array(
1 => array(
'partId' => 1,
'contentType' => 'text/plain',
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'iso-8859-1'
),
'id' => '',
'description' => '',
'encoding' => 'quoted-printable',
'size' => 1726,
'disposition' => '',
'language' => '',
'location' => '',
),
2 => array(
'partId' => 2,
'contentType' => 'text/html',
'type' => 'text',
'subType' => 'html',
'parameters' => array (
'charset' => 'iso-8859-1'
),
'id' => '',
'description' => '',
'encoding' => 'quoted-printable',
'size' => 10713,
'disposition' => '',
'language' => '',
'location' => '',
)
),
'parameters' => array (
'boundary' => '=_m192h4woyec67braywzx'
),
'disposition' => '',
'language' => '',
'location' => '',
);
$message = $this->messageTestHelper('multipart_alternative.eml', 'multipart/alternative');
$structure = $message['structure'];
$lines = $this->_getLinesFromPartsAndRemoveFromStructure($structure);
$this->assertEquals($expectedStructure, $structure, 'structure does not match');
$this->assertTrue(in_array($lines[1], array(49, 50)));
$this->assertTrue(in_array($lines[2], array(172, 173)));
}
/**
* get lines from structure parts and remove them from structure array
*
* @param array $_structure
* @return array
*/
protected function _getLinesFromPartsAndRemoveFromStructure(&$_structure)
{
$lines = array();
foreach ($_structure['parts'] as $key => $part) {
$lines[$key] = $part['lines'];
unset($_structure['parts'][$key]['lines']);
}
return $lines;
}
/**
* testBodyStructureMultipartMixed
*/
public function testBodyStructureMultipartMixed()
{
$expectedStructure = array(
'partId' => null,
'contentType' => 'multipart/mixed',
'type' => 'multipart',
'subType' => 'mixed',
'parts' => array(
1 => array(
'partId' => 1,
'contentType' => Felamimail_Model_Message::CONTENT_TYPE_PLAIN,
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'us-ascii'
),
'id' => null,
'description' => null,
'encoding' => '7bit',
'size' => 3896,
'disposition' => array(
'type' => 'inline'
),
'language' => '',
'location' => '',
),
2 => array(
'partId' => 2,
'contentType' => Felamimail_Model_Message::CONTENT_TYPE_PLAIN,
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'us-ascii'
),
'id' => '',
'description' => '',
'encoding' => '7bit',
'size' => 2787,
'disposition' => array(
'type' => 'attachment',
),
'language' => '',
'location' => '',
)
),
'parameters' => array (
'boundary' => '0F1p//8PRICkK4MWrobbat28989323553773'
),
'disposition' => array(
'type' => 'inline'
),
'language' => '',
'location' => '',
);
$expectedParameters = array(
'foobar' => 'Test Subjäct',
'filename' => 'add-removals.1239580800.log'
);
$message = $this->messageTestHelper('multipart_mixed.eml', 'multipart/mixed');
$structure = $message['structure'];
$lines = $this->_getLinesFromPartsAndRemoveFromStructure($structure);
// attachment parameters could have different order
$parameters = $structure['parts'][2]['disposition']['parameters'];
unset($structure['parts'][2]['disposition']['parameters']);
$this->assertEquals($expectedStructure, $structure, 'structure does not match');
$this->assertEquals(Felamimail_Model_Message::CONTENT_TYPE_PLAIN, $message['body_content_type']);
$this->assertTrue(in_array($lines[1], array(61, 62)));
$this->assertTrue(in_array($lines[2], array(52, 53)));
$this->assertTrue($expectedParameters == $parameters);
}
/**
* testBodyStructureMultipartMixedWithMessageRFC822
*/
public function testBodyStructureMultipartMixedWithMessageRFC822()
{
$expectedStructure = array(
'partId' => null,
'contentType' => 'multipart/mixed',
'type' => 'multipart',
'subType' => 'mixed',
'parts' => array(
1 => array(
'partId' => 1,
'contentType' => 'text/plain',
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'ISO-8859-1',
'format' => 'flowed'
),
'id' => null,
'description' => null,
'encoding' => '7bit',
'size' => 49,
'disposition' => null,
'language' => '',
'location' => '',
),
2 => array(
'partId' => 2,
'contentType' => 'message/rfc822',
'type' => 'message',
'subType' => 'rfc822',
'parameters' => array (
'name' => '[Officespot-cs-svn] r15209 - trunk/tine20/Tinebase.eml'
),
'id' => '',
'description' => '',
'encoding' => '7bit',
'size' => 4121,
'disposition' => null,
'language' => null,
'location' => null,
'messageEnvelop' => array(
'Wed, 30 Jun 2010 13:20:09 +0200',
'[Officespot-cs-svn] r15209 - trunk/tine20/Tinebase',
array(array(
'NIL', 'NIL', 'c.weiss', 'metaways.de'
)),
array(array(
'NIL', 'NIL', 'c.weiss', 'metaways.de'
)),
array(array(
'NIL', 'NIL', 'c.weiss', 'metaways.de'
)),
array(array(
'NIL', 'NIL', 'officespot-cs-svn', 'lists.sourceforge.net'
)),
'NIL',
'NIL',
'NIL',
'<20100630112010.06CD21C059@publicsvn.hsn.metaways.net>'
),
'messageStructure' => array(
'partId' => 2,
'contentType' => 'text/plain',
'type' => 'text',
'subType' => 'plain',
'parameters' => array (
'charset' => 'us-ascii'
),
'id' => null,
'description' => null,
'encoding' => '7bit',
'size' => 1562,
'disposition' => null,
'language' => '',
'location' => '',
),
)
),
'parameters' => array (
'boundary' => '------------040506070905080909080505'
),
'disposition' => null,
'language' => '',
'location' => '',
);
$message = $this->messageTestHelper('multipart_rfc2822.eml', 'multipart/rfc2822');
$structure = $message['structure'];
$lines = $this->_getLinesFromPartsAndRemoveFromStructure($structure);
$lines[3] = $structure['parts'][2]['messageStructure']['lines'];
$lines[4] = $structure['parts'][2]['messageLines'];
unset($structure['parts'][2]['messageStructure']['lines']);
unset($structure['parts'][2]['messageLines']);
// remove disposition -> dbmail finds none, dovecot does
$structure['parts'][2]['disposition'] = null;
$this->assertEquals($expectedStructure, $structure, 'structure does not match');
$this->assertTrue(in_array($lines[1], array(4, 5)));
$this->assertEquals(NULL, $lines[2]);
$this->assertTrue(in_array($lines[3], array(33, 34)));
$this->assertTrue(in_array($lines[4], array(80, 81)));
}
/**
* testGetBodyMultipartRelated
*/
public function testGetBodyMultipartRelated()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$body = $this->_controller->getMessageBody($cachedMessage, null, Zend_Mime::TYPE_TEXT, $this->_account);
$this->assertContains('würde', $body);
}
/**
* test reading a message without setting the \Seen flag
*/
public function testGetBodyMultipartRelatedReadOnly()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$body = $this->_controller->getMessageBody($cachedMessage, null, Zend_Mime::TYPE_TEXT, $this->_account, true);
$this->assertContains('würde', $body);
// @todo check for seen flag
}
/**
* testGetBodyPlainText
*/
public function testGetBodyPlainText()
{
$cachedMessage = $this->messageTestHelper('text_plain.eml', 'text/plain');
$body = $this->_controller->getMessageBody($cachedMessage, null, Zend_Mime::TYPE_TEXT, $this->_account);
$this->assertContains('a converter script be written to', $body);
}
/**
* testGetBodyPart
*/
public function testGetBodyPart()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$part = $this->_controller->getMessagePart($cachedMessage, '2');
$this->assertContains(Zend_Mime::MULTIPART_RELATED, $part->type);
$this->assertContains("------------080303000508040404000908", $part->boundary);
$part = $this->_controller->getMessagePart($cachedMessage, '2.1');
$this->assertContains(Zend_Mime::TYPE_HTML, $part->type);
$this->assertContains(Zend_Mime::ENCODING_QUOTEDPRINTABLE, $part->encoding);
$part = $this->_controller->getMessagePart($cachedMessage, '2.2');
$this->assertContains(Zend_Mime::DISPOSITION_ATTACHMENT, $part->disposition);
$this->assertContains(Zend_Mime::ENCODING_BASE64, $part->encoding);
}
/**
* testGetCompleteMessageAsPart
*/
public function testGetCompleteMessageAsPart()
{
$cachedMessage = $this->messageTestHelper('complete.eml', 'text/service');
$messagePart = $this->_controller->getMessagePart($cachedMessage);
ob_start();
fpassthru($messagePart->getRawStream());
$out = ob_get_clean();
$this->assertContains('URL: https://service.metaways.net/Ticket/Display.html?id=3D59648', $out);
}
/**
* testGetMessagePartRfc822
*/
public function testGetMessagePartRfc822()
{
$cachedMessage = $this->messageTestHelper('multipart_rfc2822-2.eml', 'multipart/rfc2822-2');
$messagePart = $this->_controller->getMessagePart($cachedMessage, 2);
ob_start();
fpassthru($messagePart->getRawStream());
$out = ob_get_clean();
$this->assertContains('X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]', $out, 'header not found');
$this->assertContains('This component, from the feedback I have, will mostly be used on', $out, 'body not found');
}
/**
* validate fetching a complete message
*/
public function testGetCompleteMessage()
{
$cachedMessage = $this->messageTestHelper('multipart_mixed.eml', 'multipart/mixed');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('robbat2@gentoo.org', $message->from_email);
$this->assertEquals($this->_account->getId(), $message->account_id);
$this->assertEquals('Robin H. Johnson', $message->from_name);
$this->assertEquals('"Robin H. Johnson" <robbat2@stork.gentoo.org>', $message->sender);
$this->assertEquals('1', $message->text_partid);
$this->assertEquals('1', $message->has_attachment);
$this->assertEquals(null, $message->html_partid);
$this->assertEquals('9606', $message->size);
$this->assertContains("Automated Package Removal", $message->subject);
$this->assertContains('\Seen', $message->flags);
$this->assertContains('11AC BA4F 4778 E3F6 E4ED F38E B27B 944E 3488 4E85', $message->body);
$this->assertEquals('add-removals.1239580800.log', $message->attachments[0]["filename"]);
}
/**
* validate fetching a complete message in 'other' dir and check its body
*
* howto:
* - copy mails to tests/tine20/Felamimail/files/other
* - add following header:
* X-Tine20TestMessage: _filename_
* - run the test!
*/
public function testCheckOtherMails()
{
$otherFilesDir = dirname(dirname(__FILE__)) . '/files/other';
if (file_exists($otherFilesDir)) {
foreach (new DirectoryIterator($otherFilesDir) as $item) {
$filename = $item->getFileName();
if ($item->isFile() && $filename !== 'README') {
$fileName = 'other/' . $filename;
echo "\nchecking message: " . $fileName . "\n";
$cachedMessage = $this->messageTestHelper($fileName, $filename);
$message = $this->_controller->getCompleteMessage($cachedMessage);
echo $message->body;
$this->assertTrue(! empty($message->body));
}
}
}
}
/**
* validate fetching a complete message
*/
public function testGetCompleteMessage2()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('1', $message->text_partid, 'no text part found');
$this->assertEquals('1', $message->has_attachment, 'no attachments found');
$this->assertEquals('2.1', $message->html_partid, 'no html part found');
$this->assertTrue(in_array($message->size, array('38455', '38506')));
$this->assertContains("Tine 2.0 bei Metaways", $message->subject);
$this->assertContains('\Seen', $message->flags);
$this->assertContains('Autovervollständigung', $message->body);
$this->assertEquals('moz-screenshot-83.png', $message->attachments[0]["filename"]);
}
/**
* validate fetching a complete message
*/
public function testGetCompleteMessage3()
{
$cachedMessage = $this->messageTestHelper('multipart_rfc2822.eml', 'multipart/rfc2822');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('multipart/mixed', $message->content_type);
$this->assertEquals('5377', $message->size);
$this->assertContains("Fwd: [Officespot-cs-svn] r15209 - trunk/tine20/Tinebase", $message->subject);
$this->assertContains('est for parsing forwarded email', $message->body);
$this->assertEquals('message/rfc822', $message->attachments[0]["content-type"]);
}
/**
* validate fetching a complete message from amazon
*/
public function testGetCompleteMessageAmazon()
{
$cachedMessage = $this->messageTestHelper('Amazon.eml', 'multipart/amazon');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('multipart/alternative', $message->content_type);
$this->assertContains('Samsung Wave S8500 Smartphone', $message->subject);
$this->assertContains('Sie suchen Produkte aus der Kategorie Elektronik & Foto?', $message->body);
}
/**
* validate fetching a message from yahoo
*
* test was created for task #4680
*/
public function testGetCompleteMessageYahoo()
{
$cachedMessage = $this->messageTestHelper('yahoo.eml');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertContains('Bitte aktualisieren Sie Ihre Kontoeinstellungen bzw. Daten-Feeds so schnell wie möglich', $message->body);
}
/**
* validate fetching a complete message from amazon #2 -> check if images got removed correctly
*/
public function testGetCompleteMessageAmazon2()
{
$cachedMessage = $this->messageTestHelper('Amazon2.eml', 'multipart/amazon2');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertContains('Fritz Meier, wir haben Empfehlungen', $message->body);
$this->assertNotContains('<img', $message->body);
$this->assertNotContains('style="background-image:url', $message->body);
$this->assertNotContains('http://www.xing.com/img/xing/newsletter/navigation_bg.gif', $message->body);
}
/**
* validate fetching a complete message from order form
*/
public function testGetCompleteMessageOrder()
{
$cachedMessage = $this->messageTestHelper('Angebotsformular.eml', 'text/angebot');
$message = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('text/plain', $message->content_type);
$this->assertContains('Angebotsformular', $message->subject);
$this->assertContains('*Formular-Weiterleitungs-Service*', $message->body);
}
/**
* validate fetching a complete message with different encodings
*/
public function testGetCompleteMessageDifferentEncoding()
{
$cachedMessage = $this->messageTestHelper('UmlauteUTF8TextISO-8859-15Signatur.eml', 'text/different');
$message = $this->_controller->getCompleteMessage($cachedMessage);
//print_r($message->toArray());
$this->assertEquals('text/plain', $message->content_type);
$this->assertContains('Umlaute UTF8 Text + ISO-8859-15 Signatur', $message->subject);
$this->assertContains('O Ö', $message->body);
}
/**
* validate fetching a complete message (rfc2822 part)
*/
public function testGetMessageRFC822()
{
$cachedMessage = $this->messageTestHelper('multipart_rfc2822.eml', 'multipart/rfc2822');
$message = $this->_controller->getCompleteMessage($cachedMessage, 2);
$this->assertEquals('4121', $message->size);
$this->assertContains("[Officespot-cs-svn] r15209 - trunk/tine20/Tinebase", $message->subject);
$this->assertTrue(isset($message->body), 'no body found');
$this->assertContains('getLogger()->debug', $message->body);
}
/**
* validate fetching a complete message
*/
public function testGetMessageRFC822_2()
{
$cachedMessage = $this->messageTestHelper('multipart_rfc2822-2.eml', 'multipart/rfc2822-2');
$message = $this->_controller->getCompleteMessage($cachedMessage, 2);
$this->assertEquals('19131', $message->size);
$this->assertContains("Proposal: Zend_Grid", $message->subject);
$this->assertTrue(isset($message->body), 'no body found');
$this->assertContains('Bento Vilas Boas wrote', $message->body ,'string not found in body: ' . $message->body);
$this->assertEquals('smime.p7s', $message->attachments[0]["filename"]);
}
/**
* validate fetching a complete message / rfc822 with base64
*/
public function testGetMessageRFC822_3()
{
$cachedMessage = $this->messageTestHelper('multipart_rfc2822-3.eml', 'multipart/rfc2822-3');
$message = $this->_controller->getCompleteMessage($cachedMessage, 2);
$this->assertTrue(isset($message->body), 'no body found');
$this->assertContains('this is base64 encoded', $message->body ,'string not found in body: ' . $message->body);
}
/**
* test adding message with duplicate to: header
*/
public function testAddMessageToCacheDuplicateTo()
{
$cachedMessage = $this->messageTestHelper('text_plain2.eml', 'text_plain2.eml');
$this->assertGreaterThan(0, count($cachedMessage->to));
$this->assertContains('c.weiss@metaways.de', $cachedMessage->to[0], 'wrong "to" header:' . print_r($cachedMessage->to, TRUE));
$this->assertContains('online', $cachedMessage->subject);
}
/**
* test adding message with invalid date
*/
public function testAddMessageToCacheInvalidDate()
{
$cachedMessage = $this->messageTestHelper('invaliddate.eml', 'text/invaliddate');
$this->assertEquals('2010-03-01 21:39:42', $cachedMessage->sent->toString());
}
/**
* test adding message with another invalid date
*/
public function testAddMessageToCacheInvalidDate2()
{
$cachedMessage = $this->messageTestHelper('invaliddate2.eml', 'text/invaliddate2');
$this->assertEquals('2009-03-16 19:51:23', $cachedMessage->sent->toString());
}
/**
* test adding message with empty date header
*/
public function testAddMessageToCacheEmptyDate()
{
$cachedMessage = $this->messageTestHelper('empty_date_header.eml', 'empty_date_header.eml');
$this->assertEquals(0, $cachedMessage->sent->getTimestamp(), 'no timestamp should be set');
}
/**
* test forward with attachment
*/
public function testForwardMessageWithAttachment()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$forwardMessage = new Felamimail_Model_Message(array(
'account_id' => $this->_account->getId(),
'subject' => 'test forward',
'to' => array($this->getEmailAddress()),
'body' => 'aaaaaä <br>',
'headers' => array('X-Tine20TestMessage' => Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822),
'original_id' => $cachedMessage->getId(),
'attachments' => array(new Tinebase_Model_TempFile(array(
'type' => Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822,
'name' => $cachedMessage->subject,
), TRUE)),
));
$sentFolder = $this->getFolder('Sent');
Felamimail_Controller_Message_Send::getInstance()->sendMessage($forwardMessage);
$forwardedMessage = $this->searchAndCacheMessage(Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822, $this->getFolder('INBOX'));
$forwardedMessageInSent = $this->searchAndCacheMessage(Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822, $sentFolder);
$completeForwardedMessage = $this->_controller->getCompleteMessage($forwardedMessage);
$this->assertEquals(Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822, $forwardedMessage['structure']['parts'][2]['contentType']);
$this->assertEquals($cachedMessage->subject . '.eml', $forwardedMessage['structure']['parts'][2]['parameters']['name']);
$this->assertEquals($cachedMessage->subject . '.eml', $completeForwardedMessage->attachments[0]['filename']);
return $forwardedMessage;
}
/**
* get email address
*
* @return string
*/
public function getEmailAddress()
{
$config = TestServer::getInstance()->getConfig();
$email = ($config->email) ? $config->email : Tinebase_Core::getUser()->accountEmailAddress;
return $email;
}
/**
* test forward message part
*/
public function testForwardMessagePart()
{
$forwardedMessage = $this->testForwardMessageWithAttachment();
$forwardMessage = new Felamimail_Model_Message(array(
'account_id' => $this->_account->getId(),
'subject' => 'test forward part',
'to' => array($this->getEmailAddress()),
'body' => 'aaaaaä <br>',
'headers' => array('X-Tine20TestMessage' => Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 . 'part'),
'original_id' => $forwardedMessage->getId() . '_2', // part 2 is the original forwared message
'attachments' => array(new Tinebase_Model_TempFile(array(
'type' => Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822,
'name' => $forwardedMessage->subject,
), TRUE)),
));
Felamimail_Controller_Message_Send::getInstance()->sendMessage($forwardMessage);
$forwardedMessage = $this->searchAndCacheMessage(Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 . 'part', $this->getFolder('INBOX'));
$completeForwardedMessagePart = $this->_controller->getCompleteMessage($forwardedMessage, 2);
//print_r($completeForwardedMessagePart->toArray());
$this->assertTrue(! empty($completeForwardedMessagePart->headers), 'headers should not be empty');
$this->assertEquals('moz-screenshot-83.png', $completeForwardedMessagePart->attachments[0]['filename']);
}
/**
* testGetBodyPartIdMultipartAlternative
*/
public function testGetBodyPartIdMultipartAlternative()
{
$cachedMessage = $this->messageTestHelper('multipart_alternative.eml', 'multipart/alternative');
$cachedMessage->parseBodyParts();
$this->assertEquals(1, $cachedMessage->text_partid, 'did not find all partIds');
$this->assertEquals(2, $cachedMessage->html_partid, 'did not find all partIds');
}
/**
* testGetBodyPartIdMultipartMixed
*/
public function testGetBodyPartIdMultipartMixed()
{
$cachedMessage = $this->messageTestHelper('multipart_mixed.eml', 'multipart/mixed');
$cachedMessage->parseBodyParts();
$this->assertEquals(1, $cachedMessage->text_partid, 'did not find all partIds');
}
/**
* testGetBodyPartIdMultipartSigned
*/
public function testGetBodyPartIdMultipartSigned()
{
$cachedMessage = $this->messageTestHelper('multipart_signed.eml', 'multipart/signed');
$cachedMessage->parseBodyParts();
$this->assertEquals(1, $cachedMessage->text_partid, 'did not find all partIds');
}
/**
* testGetBodyPartIdMultipartRelated
*/
public function testGetBodyPartIdMultipartRelated()
{
$cachedMessage = $this->messageTestHelper('multipart_related.eml', 'multipart/related');
$cachedMessage->parseBodyParts();
$this->assertEquals(1, $cachedMessage->text_partid, 'did not find all partIds');
$this->assertEquals('2.1', $cachedMessage->html_partid, 'did not find all partIds');
}
/**
* testGetMessageWithoutFromHeader
*/
public function testGetMessageWithoutFromHeader()
{
$cachedMessage = $this->messageTestHelper('withoutfrom.eml', 'text/withoutfrom');
$completeMessage = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertContains('Hier ist Ihr Hot Web Email-Deal Angebot von M&M Computer.', $completeMessage->body);
}
/**
* testGetMessageWithCommaInTo
*/
public function testGetMessageWithCommaInTo()
{
$cachedMessage = $this->messageTestHelper('mail_to_comma.eml', 'text/comma');
$completeMessage = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('inscription@arrakeen.net', $completeMessage->to[0]);
$this->assertEquals('November 2010 Crystal Newsletter - Cut the Rope Update Released!', $completeMessage->subject);
}
/**
* testUnparseableMail
*/
public function testUnparseableMail()
{
$cachedMessage = $this->messageTestHelper('unparseable.eml', 'multipart/unparseable');
$completeMessage = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals(1, preg_match('@NIL|Content-Type: image/jpeg@', $completeMessage->body), 'parsed mail body:' . $completeMessage->body);
}
/**
* test utf8 header decode
*/
public function testUtf8HeaderDecode()
{
$cachedMessage = $this->messageTestHelper('decode_utf8_header.eml');
$completeMessage = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertEquals('"Jörn Meier" <j.meier@test.local>', $completeMessage->headers['reply-to']);
$this->assertEquals('Jörn Meier <j.meier@test.local>', $completeMessage->headers['from']);
$this->assertEquals('j.meier@test.local', $completeMessage->to[0]);
}
/**
* testLongFrom
*/
public function testLongFrom()
{
$cachedMessage = $this->messageTestHelper('longfrom.eml');
$this->assertEquals('nDqIxSoSTIC', $cachedMessage->subject);
}
/**
* testGetMessageWithQuotedPrintableDecodeProblem
*/
public function testGetMessageWithQuotedPrintableDecodeProblem()
{
$cachedMessage = $this->messageTestHelper('Terminbestaetigung.eml', 'Terminbestaetigung.eml');
$completeMessage = $this->_controller->getCompleteMessage($cachedMessage);
$this->assertContains('Veröffentlichungen, Prospekte und Ähnliches bereithalten würden.', $completeMessage->body);
}
/**
* test move to another account
*/
public function testMoveMessageToAnotherAccount()
{
$clonedAccount = $this->_cloneAccount();