source: sandbox/webservice/api/rest/mail/SendResource.php @ 6664

Revision 6664, 2.4 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Adicionada implementação para enviar email com anexo na versão 2.4

  • Property svn:executable set to *
Line 
1<?php
2
3class SendResource extends MailAdapter {
4        public function post($request){
5                // to Receive POST Params (use $this->params)
6                parent::post($request);
7
8                if($this-> isLoggedIn())
9                {
10                        // parametros recuperados conforme draft
11                        $msgForwardTo           = $this->getParam("msgForwardTo");
12                        $originalMsgID          = $this->getParam("originalMsgID");
13                        $originalUserAction     = $this->getParam("originalUserAction");
14
15                        $params['input_subject']        = $this->getParam("msgSubject");
16                        $params['input_to']                     = $this->getParam("msgTo");
17                        $params['input_cc']                     = $this->getParam("msgCcTo");
18                        $params['input_cco']            = $this->getParam("msgBccTo");
19                        $params['input_replyto']        = $this->getParam("msgReplyTo");
20                        $params['body']                         = $this->getParam("msgBody");
21                        $params['type']                         = $this->getParam("msgType") ? $this->getParam("msgType") : "plain";
22                        $params['folder'] =     
23                                $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] == "-1" ? "null" :
24                                $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
25
26                        if($this->getExpressoVersion() != "2.2" && count($_FILES))
27                        {
28                                require_once (__DIR__.'/../../../prototype/api/controller.php');
29                                $files = array();
30                                foreach( $_FILES as $name => $file )
31                                {
32                                        $files[$name] = array('name' => $file['name'],
33                                                        'type' => $file['type'],
34                                                        'source' => base64_encode(file_get_contents( $file['tmp_name'], $file['size'])),
35                                                        'size' => $file['size'],
36                                                        'error' => $file['error']
37                                        );
38                                }
39                                Controller::addFallbackHandler( 0, function($e){
40                                        throw $e;
41                                } );
42                               
43                                $result = array();
44                                $attachments_ids = array();
45                                       
46                                foreach($files as $key => $value){
47                                        $value['disposition']  = isset($value['disposition']) ?
48                                                $value['disposition'] : 'attachment';
49                                        try{
50                                                $attachment = Controller::put( array( 'concept' =>  "mailAttachment" ), $value );
51                                                $attachments_ids[] = $attachment[0]['id'];
52                                               
53                                        }catch(Exception $e){
54                                                $attachment['error'] = $e->getMessage();
55                                        }
56                                }
57                                                                               
58                                $params['attDisposition1']      = 'attachment';
59                                $params['attachments']          = json_encode($attachments_ids);
60                        }
61                        $returncode = $this->getImap()->send_mail($params);
62                        if (!$returncode || !(is_array($returncode) && $returncode['success'] == true))
63                                Errors::runException("MAIL_NOT_SENT");
64                }
65
66                $this->setResult(true);
67
68                //to Send Response (JSON RPC format)
69                return $this->getResponse();
70        }
71
72}
Note: See TracBrowser for help on using the repository browser.