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

Revision 7577, 3.0 KB checked in by pereira.jair, 11 years ago (diff)

Ticket #2507 - Correção da varíavel global DIR que estava incorreta.

  • 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(count($_FILES))
27                        {
28                                $files = array();
29                                $totalSize = 0;
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                                        $totalSize += $file['size'];
39                                }
40                               
41                                $uploadMaxFileSize = str_replace("M","",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024;
42                                if($totalSize > $uploadMaxFileSize){
43                                        Errors::runException("MAIL_NOT_SENT_LIMIT_EXCEEDED", $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']);
44                                }
45
46                                if($this->getExpressoVersion() != "2.2")
47                                {
48
49                                        $fileInclude = apiDirectory.'/../../../prototype/api/controller.php';
50                                        try {
51                                                require_once ($fileInclude);
52
53                                                Controller::addFallbackHandler(0,$this->fallBackHandler($e));
54                                        } catch (Exception $e) {
55                                                Errors::runException($e->getMessage());
56                                        }
57
58                                        $result = array();
59                                        $attachments_ids = array();
60                                               
61                                        foreach($files as $key => $value){
62                                                $value['disposition']  = isset($value['disposition']) ?
63                                                        $value['disposition'] : 'attachment';
64                                                try{
65                                                        $attachment = Controller::put( array( 'concept' =>  "mailAttachment" ), $value );
66                                                        $attachments_ids[] = $attachment[0]['id'];
67                                                }catch(Exception $e){
68                                                        Errors::runException($e->getMessage());
69                                                }
70                                        }
71                                        $params['attDisposition1']      = 'attachment';
72                                        $params['attachments']          = json_encode($attachments_ids);
73                                }
74                        }
75                        $returncode = $this->getImap()->send_mail($params);
76                        if (!$returncode || !(is_array($returncode) && $returncode['success'] == true))
77                                Errors::runException("MAIL_NOT_SENT");
78                }
79
80                $this->setResult(true);
81
82                //to Send Response (JSON RPC format)
83                return $this->getResponse();
84        }
85
86        function fallBackHandler($e) {
87                throw $e;
88    }
89
90}
Note: See TracBrowser for help on using the repository browser.