## 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. */
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. class ezcMvcMailRequestParser extends ezcMvcRequestParser
34. {
35. /**
36. * Uses stdin, or the provided data in $mailMessage.
37. *
38. * @param string $mailMessage
39. * @return ezcMvcRequest
40. */
41. public function createRequest ( $mailMessage = null )
42. {
43. if ( $mailMessage === null )
44. {
45. $set = new ezcMailFileSet ( array( "php://stdin" ) );
46. }
47. else
48. {
49. $set = new ezcMailVariableSet ( $mailMessage );
50. }
51. $parser = new ezcMailParser ();
52. $mail = $parser->parseMail( $set );
53. if ( count ( $mail ) == 0 )
54. {
55. throw new ezcMvcMailNoDataException ();
56. }
57. $mail = $mail[0];
59. $this-> request = new ezcMvcRequest ();
60. $this-> processStandardHeaders ( $mail );
61. $this-> processAcceptHeaders ( $mail );
62. $this-> processUserAgentHeaders ( $mail );
63. $this-> processFiles ( $mail );
65. $this-> request ->raw = $mail;
67. return $this-> request ;
68. }
70. /**
71. * Processes the standard headers that are not subdivided into other structs.
72. *
73. * @param ezcMail $mail
74. */
75. protected function processStandardHeaders ( ezcMail $mail )
76. {
77. $req = $this-> request ;
78. $req->date = isset( $mail->timestamp )
79. ? new DateTime( "@{$mail->timestamp}

" )
- : new DateTime();
- $req->protocol = 'mail';
- $email = $mail->to[0]->email;
- $req->host = substr ( strrchr ( $email, '@' ), 1 );
- $req->uri = substr ( $email, 0, strrpos ( $email, '@' ) );
- $req->requestId = $req->host . '/' . $req->uri;
- $req->referrer = isset( $mail->headers['In-Reply-To'] )
- ? trim ( $mail->headers['In-Reply-To'], '<>' )
- : trim ( substr ( $mail->headers['References'], 0, strpos ( $mail->headers['References'], ' ' ) -1 ), '<>' );
- // As variables we'll add the from name/address and subject
- $req->variables = array(
- 'fromAddress' => $mail->from->email,
- 'fromName' => $mail->from->name,
- 'subject' => $mail->subject,
- );
- // For the body, we take the first ezcMailText part we can find. If
- // that's not enough, the rest can be accesible through raw.
- $context = new ezcMailPartWalkContext ( array( $this, 'getBody' ) );
- $context->filter = array( 'ezcMailText' );
- $mail->walkParts( $context, $mail );
- }
- /**
- * Sets the request body to the text of the $mailText if the body is empty.
- *
- * @param ezcMailPartWalkContext $context
- * @param ezcMailText $mailText
- * @access private
- */
- public function getBody ( ezcMailPartWalkContext $context, ezcMailText $mailText )
- {
- if ( $this-> request ->body == '' )
- {
- $this-> request ->body = $mailText->text;
- }
- }
- /**
- * Does really nothing, as Mail doesn't have those bits.
- */
- protected function processAcceptHeaders ()
- {
- $this-> request ->accept = new ezcMvcRequestAccept ;
- }
- /**
- * Processes the User Agent header into the ezcMvcRequestUserAgent struct.
- *
- * @param ezcMail $mail
- */
- protected function processUserAgentHeaders ( ezcMail $mail )
- {
- $this-> request ->agent = new ezcMvcRequestUserAgent ;
- $agent = $this-> request ->agent;
- $agent->agent = isset( $mail->headers['User-Agent'] )
- ? $mail->headers['User-Agent']
- : null;
- }
- /**
- * Processes file attachments.
- *
- * @param ezcMail $mail
- */
- protected function processFiles ( ezcMail $mail )
- {
- $context = new ezcMailPartWalkContext ( array( $this, 'addFile' ) );
- $context->filter = array( 'ezcMailFile' );
- $mail->walkParts( $context, $mail );
- }
- /**
- * Adds a found attachment to the request structure.
- *
- * @param ezcMailPartWalkContext $context
- * @param ezcMailFile $mailFile
- * @access private
- */
- public function addFile ( ezcMailPartWalkContext $context, ezcMailFile $mailFile )
- {
- $file = new ezcMvcRequestFile ;
- $file->mimeType = $mailFile->contentType . '/' . $mailFile->mimeType;
- $file->name = $mailFile->contentDisposition->displayFileName;
- $file->size = $mailFile->size;
- $file->status = 0;
- $file->tmpPath = $mailFile->fileName;
- $this-> request ->files[] = $file;
- }
- }
- ?>
Documentation generated by phpDocumentor 1.4.3