Apache Zeta Components Manual :: File Source for mail.php

Source for file mail.php

Documentation is available at mail.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package MvcMailTiein
  25.  */
  26.  
  27. /**
  28.  * Request parser that uses an e-mail message to populate an ezcMvcRequest object.
  29.  * @package MvcMailTiein
  30.  * @version //autogentag//
  31.  * @mainclass
  32.  */
  33. {
  34.     /**
  35.      * Uses stdin, or the provided data in $mailMessage.
  36.      *
  37.      * @param string $mailMessage 
  38.      * @return ezcMvcRequest 
  39.      */
  40.     public function createRequest$mailMessage null )
  41.     {
  42.         if $mailMessage === null )
  43.         {
  44.             $set new ezcMailFileSetarray"php://stdin" ) );
  45.         }
  46.         else
  47.         {
  48.             $set new ezcMailVariableSet$mailMessage );
  49.         }
  50.         $parser new ezcMailParser();
  51.         $mail $parser->parseMail$set );
  52.         if count$mail == )
  53.         {
  54.             throw new ezcMvcMailNoDataException();
  55.         }
  56.         $mail $mail[0];
  57.  
  58.         $this->request = new ezcMvcRequest();
  59.         $this->processStandardHeaders$mail );
  60.         $this->processAcceptHeaders$mail );
  61.         $this->processUserAgentHeaders$mail );
  62.         $this->processFiles$mail );
  63.  
  64.         $this->request->raw $mail;
  65.  
  66.         return $this->request;
  67.     }
  68.  
  69.     /**
  70.      * Processes the standard headers that are not subdivided into other structs.
  71.      *
  72.      * @param ezcMail $mail 
  73.      */
  74.     protected function processStandardHeadersezcMail $mail )
  75.     {
  76.         $req $this->request;
  77.         $req->date = isset$mail->timestamp )
  78.             ? new DateTime"@{$mail->timestamp})
  79.             : new DateTime();
  80.         $req->protocol 'mail';
  81.         $email $mail->to[0]->email;
  82.         $req->host substrstrrchr$email'@' ));
  83.         $req->uri substr$email0strrpos$email'@' ) );
  84.         $req->requestId $req->host '/' $req->uri;
  85.         $req->referrer = isset$mail->headers['In-Reply-To')
  86.             ? trim$mail->headers['In-Reply-To']'<>' )
  87.             : trimsubstr$mail->headers['References']0strpos$mail->headers['References']' ' -)'<>' );
  88.  
  89.         // As variables we'll add the from name/address and subject
  90.         $req->variables array(
  91.             'fromAddress' => $mail->from->email,
  92.             'fromName'    => $mail->from->name,
  93.             'subject'     => $mail->subject,
  94.         );
  95.  
  96.         // For the body, we take the first ezcMailText part we can find. If
  97.         // that's not enough, the rest can be accesible through raw.
  98.         $context new ezcMailPartWalkContextarray$this'getBody' ) );
  99.         $context->filter array'ezcMailText' );
  100.         $mail->walkParts$context$mail );
  101.     }
  102.  
  103.     /**
  104.      * Sets the request body to the text of the $mailText if the body is empty.
  105.      *
  106.      * @param ezcMailPartWalkContext $context 
  107.      * @param ezcMailText $mailText 
  108.      * @access private
  109.      */
  110.     public function getBodyezcMailPartWalkContext $contextezcMailText $mailText )
  111.     {
  112.         if $this->request->body == '' )
  113.         {
  114.             $this->request->body $mailText->text;
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * Does really nothing, as Mail doesn't have those bits.
  120.      */
  121.     protected function processAcceptHeaders()
  122.     {
  123.         $this->request->accept new ezcMvcRequestAccept;
  124.     }
  125.  
  126.     /**
  127.      * Processes the User Agent header into the ezcMvcRequestUserAgent struct.
  128.      *
  129.      * @param ezcMail $mail 
  130.      */
  131.     protected function processUserAgentHeadersezcMail $mail )
  132.     {
  133.         $this->request->agent new ezcMvcRequestUserAgent;
  134.         $agent $this->request->agent;
  135.  
  136.         $agent->agent = isset$mail->headers['User-Agent')
  137.             ? $mail->headers['User-Agent']
  138.             : null;
  139.     }
  140.  
  141.     /**
  142.      * Processes file attachments.
  143.      *
  144.      * @param ezcMail $mail 
  145.      */
  146.     protected function processFilesezcMail $mail )
  147.     {
  148.         $context new ezcMailPartWalkContextarray$this'addFile' ) );
  149.         $context->filter array'ezcMailFile' );
  150.         $mail->walkParts$context$mail );
  151.     }
  152.  
  153.     /**
  154.      * Adds a found attachment to the request structure.
  155.      *
  156.      * @param ezcMailPartWalkContext $context 
  157.      * @param ezcMailFile $mailFile 
  158.      * @access private
  159.      */
  160.     public function addFileezcMailPartWalkContext $contextezcMailFile $mailFile )
  161.     {
  162.         $file new ezcMvcRequestFile;
  163.         $file->mimeType $mailFile->contentType '/' $mailFile->mimeType;
  164.         $file->name $mailFile->contentDisposition->displayFileName;
  165.         $file->size $mailFile->size;
  166.         $file->status 0;
  167.         $file->tmpPath $mailFile->fileName;
  168.  
  169.         $this->request->files[$file;
  170.     }
  171. }
  172. ?>
Documentation generated by phpDocumentor 1.4.3