/
ImportMailMessage.php
100 lines (79 loc) · 2.94 KB
/
ImportMailMessage.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
<?php
// should be in import folder... need to know where this is used though...
require_once 'ConvertStyle.php';
class Pman_Core_ImportMailMessage extends Pman_Core_ConvertStyle
{
function getAuth()
{
if (HTML_FlexyFramework::get()->cli) {
return true;
}
$this->authUser = $this->getAuthUser();
if (!$this->authUser) {
return false;
}
return true;
}
function get($v, $opts=array())
{
$this->post();
return $this->jerr("not allowed");
}
function post($v)
{
if(isset($_REQUEST['_convertToPlain']))
{
require_once 'System.php';
$tmpdir = System::mktemp("-d convertPlain");
$path = $tmpdir . '/' . time() . '.html';
if(isset($_REQUEST['_check_unsubscribe'])){
libxml_use_internal_errors (true);
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($_REQUEST['bodytext']);
$xpath = new DOMXpath($doc);
foreach ($xpath->query('//a[@href]') as $a) {
$href = $a->getAttribute('href');
if(!preg_match('/^#unsubscribe/', $href)){
continue;
}
$a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
}
$_REQUEST['bodytext'] = $doc->saveHTML();
libxml_use_internal_errors (false);
}
if(!file_exists($path)){
file_put_contents($path, $_REQUEST['bodytext']);
}
require_once 'File/Convert.php';
$fc = new File_Convert($path, 'text/html');
$plain = $fc->convert('text/plain');
$this->jok(file_get_contents($plain));
}
// Import from URL
if(isset($_REQUEST['importUrl']))
{
$this->checkHeader($_REQUEST['importUrl']);
$data = $this->convertStyle($_REQUEST['importUrl'], '', true);
$this->jok($data);
}
// Import from file
$htmlFile = DB_DataObject::factory('images');
$htmlFile->setFrom(array(
'onid' => 0,
'ontable' =>'crm_mailing_list_message'
));
$htmlFile->onUpload(false);
if($htmlFile->mimetype != 'text/html')
{
$this->jerr('accept html file only!');
}
if(!file_exists($htmlFile->getStoreName()))
{
$this->jerr('update failed!');
}
$data = $this->convertStyle('', $htmlFile->getStoreName(), false);
$htmlFile->delete();
unlink($htmlFile->getStoreName()) or die('Unable to delete the file');
$this->jok($data);
}
}