5 require_once 'Pman.php';
7 class Pman_Core_Import_Core_email extends Pman
9 static $cli_desc = "Import an email into core_email template";
11 static $cli_opts = array(
13 'desc' => 'File to import',
24 $ff = HTML_FlexyFramework::get();
32 function get($part='', $opts){
35 $template_name = preg_replace('/\.[a-z]+$/i', '', basename($opts['file']));
37 if (!file_exists($opts['file'])) {
38 $this->jerr("file does not exist : " . $opts['file']);
41 $c = DB_dataObject::factory('core_email');
42 $ret = $c->get('name',$template_name);
44 $this->jerr("we do not support updating the files ... - especially if the user has changed them!!");
47 $mailtext = file_get_contents($opts['file']);
49 require_once 'Mail/mimeDecode.php';
50 require_once 'Mail/RFC822.php';
52 $decoder = new Mail_mimeDecode($mailtext);
53 $parts = $decoder->getSendArray();
56 $from = new Mail_RFC822();
57 $from_str = $from->parseAddressList($headers['From']);
59 $from_name = trim($from_str[0]->personal, '"');
61 $from_email = $from_str[0]->mailbox . '@' . $from_str[0]->host;
65 'from_name' => $from_name,
66 'from_email' => $from_email,
67 'subject' => $parts[1]['Subject'],
68 'name' => $template_name,
69 'bodytext' => $parts[2]