Beispiel #1
0
 /**
  *
  */
 public function createAction($argv)
 {
     $params = $this->parseArgs($argv, ['title' => 'Add a user with a permission role.', 'args' => ['required' => ['email', 'role'], 'optional' => []], 'opts' => ['p|password:'******'set user password (otherwise it will need to be on first login).', 'a|activate' => 'activate', 'E|send-email?' => 'send email confirmation with optional message']]);
     list($emailRaw, $roleRef) = $params['args'];
     $opts = $params['opts'];
     $emailParts = mailparse_rfc822_parse_addresses($emailRaw);
     if (empty($emailParts) || $emailParts[0]['display'] == $emailParts[0]['address']) {
         throw new ArgumentValidationException('Email must be in form: display <address>', 1);
     }
     $name = $emailParts[0]['display'];
     $email = $emailParts[0]['address'];
     // Validate the email
     if (($email = filter_var($email, FILTER_VALIDATE_EMAIL)) === false) {
         throw new ArgumentValidationException('Email is invalid', 1);
     }
     $role = $this->getRoleByUniqueRef($roleRef);
     // Validate the password
     if (isset($opts['password'])) {
         $password = $opts['password'];
         $passwordMinLength = $this->config->security->passwordMinLength;
         if (mb_strlen($password) < $passwordMinLength) {
             throw new ArgumentValidationException("Password must be at least {$passwordMinLength} characters", 1);
         }
     } else {
         // The model will check for an empty string and will create a random password
         $password = '';
     }
     // Check for CLI flags
     $active = isset($opts['activate']) ? 'Y' : 'N';
     $sendEmail = array_key_exists('send-email', $opts);
     $emailExtraMsg = isset($opts['send-email']) ? trim($opts['send-email']) : '';
     $user = new Users();
     $user->assign(['name' => $name, 'rolesId' => $role->id, 'email' => $email, 'active' => $active, 'password' => $password]);
     if (!$user->save()) {
         $message = implode("\n", $user->getMessages());
         throw new \Exception("{$message}", 1);
     }
     if ($sendEmail) {
         echo "Sending email confirmation to user\n";
         $emailConfirmation = new EmailConfirmations();
         $emailConfirmation->usersId = $user->id;
         $emailConfirmation->extraMsg = $emailExtraMsg;
         if (!$emailConfirmation->save()) {
             $message = implode("\n", $emailConfirmation->getMessages());
             throw new \Exception($message, 1);
         }
     }
 }
Beispiel #2
0
 function user_match_to($user, $to_hdr)
 {
     $incoming = $user->incomingemail;
     $tos = mailparse_rfc822_parse_addresses($to_hdr);
     foreach ($tos as $to) {
         if (strcasecmp($incoming, $to['address']) == 0) {
             return true;
         }
     }
     return false;
 }
Beispiel #3
0
 /**
  * @param string $addresses A string containing addresses, like in: Wez Furlong <*****@*****.**>, doe@example.com
  *
  * @return array Returns an array of associative arrays with the following keys for each recipient:
  *               - display  => The recipient name, for display purpose. If this part is not set for a recipient,
  *                             this key will hold the same value as address.
  *               - address  => The email address
  *               - is_group => TRUE if the recipient is a newsgroup, FALSE otherwise.
  */
 public static function parseRFC822Addresses(string $addresses)
 {
     return mailparse_rfc822_parse_addresses($addresses);
 }
Beispiel #4
0
 /**
  * Return an array with the following keys display, address, is_group
  *
  * @param string $name Header name (case-insensitive)
  *
  * @return array
  */
 public function getAddresses($name)
 {
     $value = $this->getHeader($name);
     return mailparse_rfc822_parse_addresses($value);
 }
/**
 * extract_from_email()
 * See extract_email
 * @param string $str
 * @return string
 */
function extract_email($str)
{
    $arr = mailparse_rfc822_parse_addresses($str);
    if (is_array($arr) && !empty($arr)) {
        foreach ($arr as $item) {
            return strtolower($item['address']);
        }
    }
    // if that didn't work:
    preg_match('/[\\w\\.\\-+=*_]*@[\\w\\.\\-+=*_]*/', $str, $m);
    if (!empty($m[1])) {
        return $m[1];
    }
    return false;
}
Beispiel #6
0
 /**
  * Checks that an email is valid using the mailparse extension if available.
  *
  * @param string $email The email to be validated.
  * @return bool True if valid, false otherwise.
  */
 protected function checkValidEmail($email)
 {
     if (function_exists('mailparse_rfc822_parse_addresses')) {
         $parsed = mailparse_rfc822_parse_addresses($email);
         if (count($parsed) > 0 && array_key_exists('address', $parsed[0])) {
             $email = $parsed[0]['address'];
         } else {
             return false;
         }
     }
     return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
 }
Beispiel #7
0
    $received = array("from mail pickup service by hotmail.com with Microsoft", "from 66.178.40.49 by BAY116-DAV8.phx.gbl with DAV;");
    VS($info, array("headers" => array("received" => $received), "starting-pos" => 0, "starting-pos-body" => 200, "ending-pos" => 200, "ending-pos-body" => 200, "line-count" => 6, "body-line-count" => 0, "charset" => "us-ascii", "transfer-encoding" => "8bit", "content-type" => "text/plain", "content-base" => "/"));
}
//////////////////////////////////////////////////////////////////////
$addresses = array("\":sysmail\"@ Some-Group. Some-Org, Muhammed." . "(I am the greatest) Ali @(the)Vegas.WBA", "\"strange\":\":sysmail\"@ Some-Group. Some-Org, Muhammed." . "(I am the greatest) Ali @(the)Vegas.WBA;");
ob_start();
foreach ($addresses as $first => $second) {
    $parsed = mailparse_rfc822_parse_addresses($second);
    foreach ($parsed as $pfirst => $psecond) {
        $pair = $psecond;
        echo $pair['display'];
        echo "\n";
        echo $pair['address'];
        echo "\n";
        if ($pair['is_group']) {
            $sub = mailparse_rfc822_parse_addresses(substr($pair['address'], 1, strlen($pair['address']) - 2));
            foreach ($sub as $blah) {
                echo "   ";
                echo $blah['address'];
                echo "\n";
            }
        }
    }
    echo "...\n";
}
$output = ob_get_contents();
ob_end_clean();
VS($output, ":sysmail@Some-Group.Some-Org\n" . "\":sysmail\"@Some-Group.Some-Org\n" . "I am the greatest the\n" . "Muhammed.Ali@Vegas.WBA\n" . "...\n" . "strange\n" . ":\":sysmail\"@Some-Group.Some-Org,Muhammed.Ali@Vegas.WBA;\n" . "   \":sysmail\"@Some-Group.Some-Org\n" . "   Muhammed.Ali@Vegas.WBA\n" . "...\n");
//////////////////////////////////////////////////////////////////////
$text = "hello, this is some text=hello.";
$fp = tmpfile();
<?php

require_once __DIR__ . '/../phplib/util.php';
require_once __DIR__ . '/../phplib/mime-mail-parser/MimeMailParser.class.php';
log_scriptLog("getWotdImageByEmail: starting");
$validSenderAddress = Config::get("WotD.imageEmailSender") or die("No image email sender in config file\r\n");
$validHeight = Config::get("WotD.wotdImageHeight") or die("No image height in config file\r\n");
$validWidth = Config::get("WotD.wotdImageWidth") or die("No image width in config file\r\n");
$daysInterval = Config::get("WotD.interval") or die("No days interval in config file\r\n");
$email = file_get_contents("php://stdin");
$Parser = new MimeMailParser();
$Parser->setText($email);
$sender = $Parser->getHeader("from");
$subject = imap_utf8($Parser->getHeader("subject"));
$parsedSender = mailparse_rfc822_parse_addresses($sender);
if (count($parsedSender) != 1 || $parsedSender[0]['address'] !== $validSenderAddress) {
    OS::errorAndExit("Ignoring message '{$subject}' due to invalid sender '{$sender}'", 0);
}
$word = GetWotdFromSubject($subject);
$attachments = $Parser->getAttachments();
if (empty($attachments)) {
    OS::errorAndExit("Ignoring message '{$subject}' because it has no attachments", 0);
} elseif (count($attachments) > 1) {
    OS::errorAndExit("Ignoring message '{$subject}' because it has more than 1 attachment", 0);
}
$contentType = $attachments[0]->content_type;
if (!StringUtil::startsWith($contentType, "image/")) {
    OS::errorAndExit("Ignoring message '{$subject}' because its attachment is not an image", 0);
}
$image = $attachments[0]->content;
$imageExtension = $attachments[0]->getFileExtension();
Beispiel #9
0
$final_message_content = preg_replace('/(<br[^>]*>\\s*){2,}/', '<br/>', $final_message_content);
//mb_convert_encoding($str, "UTF-8",
//fwrite($fp, "\n\n text/plain content:".$final_message_content);
//$task_from_php_email = $base_header['headers']['x-ofuz-emailer'];
$email_sub = $base_header['headers']['subject'];
$raw_to = $base_header['headers']['to'];
$raw_cc = $base_header['headers']['cc'];
$raw_from = $base_header['headers']['from'];
//$raw_cc =  $info['headers']['cc'];
// as bcc are invisible replaced by original_target
//$bcc = $info['headers']['bcc'];
$bcc = $original_target;
$to_parsed = mailparse_rfc822_parse_addresses($raw_to);
$cc_parsed = mailparse_rfc822_parse_addresses($raw_cc);
$bcc_parsed = mailparse_rfc822_parse_addresses($bcc);
$from_parsed = mailparse_rfc822_parse_addresses($raw_from);
$to_namerr = array();
$to_emailarr = array();
$email_marged_array = array();
$email_marged_array_task = array();
//$email_marged_array = array_merge($to_parsed,$cc_parsed,$bcc_parsed);
$email_marged_array = array_merge($to_parsed, $bcc_parsed);
$code_found = false;
$addnote = false;
$addtask = false;
$addprojectnote = false;
$add_project_task = false;
//fwrite($fp, "\nEmail array:".$email_marged_array);
/*
From the marge array for To/BCC get the email ids and
out in a seperate id and get the array length
 /**
  * Function get the email "bcc"
  * @return array with email 
  * Check the received story for the email id 
  * @see mailparse_rfc822_parse_addresses
  * @see http://php.net/manual/en/function.mailparse-rfc822-parse-addresses.php
  */
 public function getBCCEmail()
 {
     $regexp = "/for \\<(.*?)\\>;/i";
     if (preg_match($regexp, $this->received_story, $receive_matches)) {
         $original_target = $receive_matches[1];
     }
     if (isset($original_target)) {
         return mailparse_rfc822_parse_addresses($original_target);
     }
 }