[7342] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class 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 | require_once (__DIR__.'/../../../prototype/api/controller.php'); |
---|
| 49 | Controller::addFallbackHandler( 0, function($e){ |
---|
| 50 | throw $e; |
---|
| 51 | } ); |
---|
| 52 | |
---|
| 53 | $result = array(); |
---|
| 54 | $attachments_ids = array(); |
---|
| 55 | |
---|
| 56 | foreach($files as $key => $value){ |
---|
| 57 | $value['disposition'] = isset($value['disposition']) ? |
---|
| 58 | $value['disposition'] : 'attachment'; |
---|
| 59 | try{ |
---|
| 60 | $attachment = Controller::put( array( 'concept' => "mailAttachment" ), $value ); |
---|
| 61 | $attachments_ids[] = $attachment[0]['id']; |
---|
| 62 | }catch(Exception $e){ |
---|
| 63 | Errors::runException($e->getMessage()); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | $params['attDisposition1'] = 'attachment'; |
---|
| 67 | $params['attachments'] = json_encode($attachments_ids); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | $returncode = $this->getImap()->send_mail($params); |
---|
| 71 | if (!$returncode || !(is_array($returncode) && $returncode['success'] == true)) |
---|
| 72 | Errors::runException("MAIL_NOT_SENT"); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | $this->setResult(true); |
---|
| 76 | |
---|
| 77 | //to Send Response (JSON RPC format) |
---|
| 78 | return $this->getResponse(); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | } |
---|