* @license PHP License * @package WB * @subpackage MailMime */ WBClass::load('WBCli' , 'WBObserver'); /** * Command Line Interface class: Event Queue Processor * * Run event queue * * @version 0.1.1 * @package WB * @subpackage MimeMail */ class WBCli_Procmail extends WBCli implements WBObserver { /** * Command line arguments * @var array */ protected $arguments = array( CONSOLE_GETARGS_PARAMS => array( 'min' => 1, 'max' => -1, 'default' => 'Save', 'desc' => 'Processor and optional commands', ) ); /** * Mail processor * * @var WBMail_Mime_Processor */ private $proc; /** * Incomming mail loader * * @var WBMail_Mime_Storage_String */ private $in; /** * Incomming mail * * @var WBMail_Mime */ private $mail; /** * 2nd constructor * * load config and setup importer */ protected function init() { } /** * execute programme * * Use observer and execute event queue */ protected function execute() { if (empty($this->commands)) { $this->commands = array('Save'); } $this->debugPrint('Commands: ' . implode(' ', $this->commands), 10); // load processor $this->proc = WBClass::create('WBMail_Mime_Processor_' . $this->commands[0]); if (!$this->proc) { $this->pl('Could not start mime mail processor: ' . $this->commands[0] . '!'); return 1; } $subject = WBClass::create('WBMail_Mime_Processor_Observable_Cli'); $subject->setObserver($this); $this->proc->setObservable($subject); array_shift($this->commands); $this->pv(get_class($this->proc)); $this->pvl(' ' . implode(', ', $this->commands)); $this->in = WBClass::create('WBMail_Mime_Storage_String'); // load mail from STDIN $in = ''; while (!feof(STDIN)) { $in .= fgets(STDIN, 4096); } $this->pvl('Mime-Mail-Size: ' . strlen($in)); $this->in->loadFromString($in); $in = ''; // Get some e-mail information $this->mail = $this->in->getMimeMail(); $from = $this->mail->getFrom(); $this->pvl('From: "' . $from->getForename() . ' ' . $from->getSurname() . '" <' . $from->getEmailAddress() . '>'); $this->pvl('Subject: "' . $this->mail->getSubject() . '"'); $this->pvl('Text-Size: ' . strlen($this->mail->getPlainBody())); $this->pvl('Attachments: ' . $this->mail->countAttachments()); // execute $this->proc->setMimeMail($this->mail); $this->proc->execute($this->commands); } /** * get help text - head * * Override this method to set suitable help text * * @return string */ protected function getHelpHead() { $head = array(); $head[] = 'Wombat Procmail - Generic Mail Processor'; $head[] = ''; $head[] = 'Procmail is a generic mail processor to connect any Wombat toolkit to the MTA.'; $head[] = 'It simply reads an e-mail from STDIN and transforms it to an WBMail_Mime object.'; $head[] = 'Then, the actual processing starts. Processors are implemented in classes in'; $head[] = 'WB/Mail/Mime/Processor/*'; $head[] = ''; $head[] = 'Usage: ' . basename($_SERVER['_']) . ' [OPTION]... COMMAND... '; $head[] = 'Options:'; $head[] = ''; return implode("\n", $head); } /** * Get informed * * @param WBMail_Mime_Processor_Observerable_Cli $subject */ public function update($subject) { $this->pl($subject->getMsg()); } }