Server IP : 172.67.216.182 / Your IP : 172.71.81.144 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/coircraft.com/wp-content/plugins/wp-mail-logging/src/ |
Upload File : |
<?php namespace No3x\WPML; use No3x\WPML\Model\WPML_Mail as Mail; class WPML_MailExtractor { const ERROR_NO_FIELD = "The message is not valid because it contains no message or html field."; public function __construct() { } public function extract($mailArray) { return Mail::create([ 'receiver' => $this->extractReceiver($mailArray['to']), 'subject' => $mailArray['subject'], 'message' => $this->extractMessage($mailArray), 'headers' => $this->extractHeader($mailArray), 'attachments' => $this->extractAttachments($mailArray), ]); } private function extractReceiver( $receiver ) { return $this->convertMultipartsToString($receiver); } private function extractMessage( $mail ) { if ( isset($mail['message']) ) { // usually the message is stored in the message field return $mail['message']; } elseif ( isset($mail['html']) ) { // for example Mandrill stores the message in the 'html' field (see gh-22) return $mail['html']; } throw new \Exception(self::ERROR_NO_FIELD); } private function extractHeader( $mail ) { $headers = isset($mail['headers']) ? $mail['headers'] : array(); return $this->joinMultiParts($headers); } private function extractAttachments( $mail ) { $attachmentAbsPaths = isset($mail['attachments']) ? $mail['attachments'] : array(); if(!is_array($attachmentAbsPaths)) { $attachmentAbsPaths = $this->splitAtComma($attachmentAbsPaths); } $attachment_urls = []; foreach ($attachmentAbsPaths as $attachmentAbsPath) { $attachment = WPML_Attachment::fromAbsPath($attachmentAbsPath); $attachment_urls[] = $attachment->toRelPath(); } $string = $this->joinArrayWithCommaAndNewLine($attachment_urls); return $string; } private function convertMultipartsToString($multiparts) { if(is_array($multiparts)) { $multiPartArray = $multiparts; } else { $multiPartArray = $this->splitAtComma($multiparts); } $string = $this->joinArrayWithCommaAndNewLine($multiPartArray); return $string; } private function splitAtComma($string) { $parts = preg_split( "/(,|,\s)/", $string ); return $parts; } private function joinMultiParts($multiPart) { return is_array($multiPart) ? $this->joinArrayWithCommaAndNewLine($multiPart) : $multiPart; } private function joinArrayWithCommaAndNewLine(array $array) { return implode(',\n', $array); } }