Пример #1
0
 function shootEmail($email)
 {
     $addr = $email["to"];
     $msg = $email["body"];
     $sub = $email["subject"];
     $type = $email["type"];
     $dummy = $_POST["dont_send_email"];
     // New email object wrapper takes care of logging etc.
     $email = new email_send($addr, $sub, $msg, $type);
     // REMOVE ME!!
     #$email->ignore_no_email_urls = true;
     if ($dummy) {
         return "Elected not to send email.";
     } else {
         if (!$email->is_valid_url()) {
             return "Almost sent email to: " . $email->to_address;
         } else {
             if (!$email->to_address) {
                 return "Could not send email, invalid email address: " . $email->to_address;
             } else {
                 if ($email->send()) {
                     return "Sent email to: " . $email->to_address;
                 } else {
                     return "Problem sending email to: " . $email->to_address;
                 }
             }
         }
     }
 }
Пример #2
0
 function send_emails($selected_option, $email_receive = false, $hash = "", $is_a_reply_comment = false, $files = array())
 {
     $current_user =& singleton("current_user");
     $e = $this->get_parent_object();
     $type = $e->classname . "_comments";
     $body = $this->get_value("comment");
     if (is_object($email_receive)) {
         list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]);
     }
     if ($is_a_reply_comment) {
         $id = $this->get_value("commentLinkID");
     } else {
         $id = $this->get_id();
     }
     $recipients = comment::get_email_recipients($selected_option, "comment", $id);
     list($to_address, $bcc, $successful_recipients) = comment::get_email_recipient_headers($recipients, $from_address);
     if ($to_address || $bcc || $successful_recipients) {
         $email = new email_send();
         if ($email_receive) {
             list($email_receive_header, $email_receive_body) = $email_receive->get_raw_header_and_body();
             $email->set_headers($email_receive_header);
             $email->set_body($email_receive_body, $email_receive->mail_text);
             // Remove any existing To/Cc header, to prevent the email getting sent to the same recipients again.
             $email->del_header("To");
             $email->del_header("Cc");
             $subject = $email->get_header("subject");
             $subject = trim(preg_replace("/{Key:[^}]*}.*\$/i", "", $subject));
         } else {
             $email->set_body($body);
             if ($files) {
                 // (if we're bouncing a complete email body the attachments are already included, else do this...)
                 foreach ((array) $files as $file) {
                     $email->add_attachment($file["fullpath"]);
                 }
             } else {
                 $email->set_content_type();
             }
         }
         $bcc && $email->add_header("Bcc", $bcc);
         // nuke bounce headers - mail won't send properly otherwise
         $email->del_header("Resent-From");
         $email->del_header("Resent-Date");
         $email->del_header("Resent-Message-ID");
         $email->del_header("Resent-To");
         $email->add_header("X-Alloc-CommentID", $this->get_id());
         if (is_object($e) && method_exists($e, "get_name")) {
             $email->add_header("X-Alloc-" . ucwords($e->classname), $e->get_name());
             $email->add_header("X-Alloc-" . ucwords($e->key_field->get_name()), $e->get_id());
         }
         // Add project header too, if possible
         if (has("project") && $e->classname != "project" && isset($e->data_fields["projectID"])) {
             $p = $e->get_foreign_object("project");
             $email->add_header("X-Alloc-Project", $p->get_value("projectName"));
             $email->add_header("X-Alloc-ProjectID", $p->get_id());
         }
         $email->set_to_address($to_address);
         $messageid = $email->set_message_id($hash);
         $subject_extra = "{Key:" . $hash . "}";
         $email->set_date();
         if (!$subject) {
             $tpl = config::get_config_item("emailSubject_" . $e->classname . "Comment");
             $tpl and $subject = commentTemplate::populate_string($tpl, $e->classname, $e->get_id());
             $e->classname != "task" and $prefix = ucwords($e->classname) . " Comment: ";
             $subject or $subject = $prefix . $e->get_id() . " " . $e->get_name(DST_VARIABLE);
         }
         $email->set_subject($subject . " " . $subject_extra);
         $email->set_message_type($type);
         // If from name is empty, then use the email address instead
         // eg: From: jon@jonny.com -> From: "jon@jonny.com via allocPSA" <*****@*****.**>
         $from_name or $from_name = $from_address;
         is_object($current_user) && !$from_name and $from_name = $current_user->get_name();
         if (defined("ALLOC_DEFAULT_FROM_ADDRESS") && ALLOC_DEFAULT_FROM_ADDRESS) {
             if (config::for_cyber()) {
                 $email->set_reply_to('"All parties via allocPSA" ' . ALLOC_DEFAULT_FROM_ADDRESS);
                 $email->set_from('"' . str_replace('"', '', $from_name) . ' via allocPSA" ' . ALLOC_DEFAULT_FROM_ADDRESS);
             } else {
                 $email->set_reply_to('"All parties" ' . ALLOC_DEFAULT_FROM_ADDRESS);
                 $email->set_from('"' . str_replace('"', '', $from_name) . '" ' . ALLOC_DEFAULT_FROM_ADDRESS);
             }
         } else {
             if (is_object($current_user) && $current_user->get_from()) {
                 $f = $current_user->get_from();
             } else {
                 $f = config::get_config_item("allocEmailAdmin");
             }
             $email->set_reply_to($f);
             $email->set_from($f);
         }
         if ($email->send(false)) {
             return array($successful_recipients, $messageid);
         }
     }
 }
Пример #3
0
 function get_commands($commands = array())
 {
     list($header, $body) = $this->get_raw_header_and_body();
     $header and $header_obj = $this->parse_headers($header);
     $subject = $header_obj["subject"];
     $e = new email_send();
     $e->set_headers($header);
     $str = $header_obj["in-reply-to"] . " " . $header_obj["references"];
     preg_match_all("/\\.alloc\\.key\\.([A-Za-z0-9]{8})@/", $str, $m);
     if (is_array($m[1])) {
         $temp = array_flip($m[1]);
         // unique pls
         foreach ($temp as $k => $v) {
             $rtn["key"][] = $k;
         }
     }
     // We now have: $header,$body,$subject
     if ($commands) {
         /* Disabled ...
               // Look for commands in the email's header
               foreach ($commands as $k=>$v) {
                 $h = trim($e->get_header("x-alloc-".$k));
                 $h and $rtn[strtolower($k)][] = $h;
               }
         
               // Look for commands in the email's body
               $lines = explode("\n",$this->mail_text);
         
               #echo "Lines: ".print_r($lines,1);
               #echo "<br>Com:".print_r($commands,1);
         
               // Loop through the email backwards, we're looking for the final paragraph of commands
               for($i=count($lines);$i>0;$i--){
                 #echo "<br>line: [".$i."]:".$lines[$i]." go:".sprintf("%d",$go)." starting_line: ".$starting_line;
                 $lines[$i] and $go = true;
                 $go && !$lines[$i] and $starting_line = $i;
               }
         
               // Loop forwards and accumulate the commands
               for($i=$starting_line-1;$i<=count($lines);$i++) {
                 foreach ($commands as $k=>$v) {
                   preg_match("/^".$k.":\s*(.*)$/i",$lines[$i],$matches);
                   if ($matches[1]) {
                     $rtn[strtolower($k)][] = trim($matches[1]);
                   }
                 }
               }
               */
         // Look for commands in the email's subject line
         preg_match("/{(Key:[^}]*)}/i", $subject, $matches);
         $subject = $matches[1];
         $bits = explode("^", $subject);
         foreach ($bits as $bit) {
             if ($bit) {
                 // ^something: value
                 $chunks = explode(":", $bit);
                 $key = trim(array_shift($chunks));
                 $val = trim(implode(":", $chunks));
                 if ($commands[strtolower($key)] && $val) {
                     $rtn[strtolower($key)][] = trim($val);
                 }
             }
         }
     }
     // we can have multiple time: entries in an email
     // all other commands are only used once per email
     foreach ((array) $rtn as $k => $v) {
         if ($k == "time") {
             $r[$k] = $v;
         } else {
             $r[$k] = end($v);
         }
     }
     return (array) $r;
 }
Пример #4
0
 } else {
     if ($_POST["new_pass"]) {
         $db = new db_alloc();
         $db->query("SELECT * FROM person WHERE emailAddress = '%s'", $_POST["email"]);
         if ($db->next_record()) {
             // generate new random password
             $password = "";
             $pwSource = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?";
             srand((double) microtime() * 1000000);
             for ($i = 0; $i < 8; $i++) {
                 $password .= substr($pwSource, rand(0, strlen($pwSource)), 1);
             }
             $q = prepare("UPDATE person SET password = '******' WHERE emailAddress = '%s'\n                 ", encrypt_password($password), $_POST["email"]);
             $db2 = new db_alloc();
             $db2->query($q);
             $e = new email_send($_POST["email"], "New Password", "Your new temporary password: "******"new_password");
             #echo "Your new temporary password: "******"message_good"][] = "New password sent to: " . $_POST["email"];
             } else {
                 $error = "Unable to send email.";
             }
         } else {
             $error = "Invalid email address.";
         }
         // Else if just visiting the page
     } else {
         if (!$sess->TestCookie()) {
             $sess->SetTestCookie();
         }
     }
Пример #5
0
 /**
  * Get a single email, add an mbox date header line
  * @param integer $emailUID the IMAP UID of an email
  * @return string a single email in mbox format
  */
 public function get_email($emailUID)
 {
     $current_user =& singleton("current_user");
     //$lockfile = ATTACHMENTS_DIR."mail.lock.person_".$current_user->get_id();
     if ($emailUID) {
         $info = $this->init_email_info();
         $mail = new email_receive($info);
         $mail->open_mailbox(config::get_config_item("allocEmailFolder"), OP_READONLY);
         list($header, $body) = $mail->get_raw_email_by_msg_uid($emailUID);
         $mail->close();
         $m = new email_send();
         $m->set_headers($header);
         $timestamp = $m->get_header('Date');
         $str = "From allocPSA " . date('D M  j G:i:s Y', strtotime($timestamp)) . "\r\n" . $header . $body;
         return utf8_encode(str_replace("\r\n", "\n", $str));
     }
 }
Пример #6
0
    $person = new person();
    $person->read_db_record($db);
    $person->set_id($db->f("personID"));
    $person->load_prefs();
    if (!$person->prefs["dailyTaskEmail"]) {
        continue;
    }
    $msg = "";
    $tasks = "";
    $to = "";
    if ($announcement["heading"]) {
        $msg .= $announcement["heading"];
        $msg .= "\n" . $announcement["body"] . "\n";
        $msg .= "\n- - - - - - - - - -\n";
    }
    if ($person->get_value("emailAddress")) {
        $tasks = $person->get_tasks_for_email();
        $msg .= $tasks;
        $subject = commentTemplate::populate_string(config::get_config_item("emailSubject_dailyDigest", ""));
        $to = $person->get_value("emailAddress");
        if ($person->get_value("firstName") && $person->get_value("surname") && $to) {
            $to = $person->get_value("firstName") . " " . $person->get_value("surname") . " <" . $to . ">";
        }
        if ($tasks && $to) {
            $email = new email_send($to, $subject, $msg, "daily_digest");
            if ($email->send()) {
                echo "\n<br>Sent email to: " . $to;
            }
        }
    }
}
Пример #7
0
 function mail_advnotice()
 {
     $date = strtotime($this->get_value('reminderTime'));
     // if no advanced notice needs to be sent then dont bother
     if ($this->get_value('reminderAdvNoticeInterval') != "No" && $this->get_value('reminderAdvNoticeSent') == 0 && !$this->get_value("reminderHash")) {
         $date = strtotime($this->get_value('reminderTime'));
         $interval = -$this->get_value('reminderAdvNoticeValue');
         $intervalUnit = $this->get_value('reminderAdvNoticeInterval');
         $advnotice_time = $this->get_next_reminder_time($date, $interval, $intervalUnit);
         // only sent advanced notice if it is time to send it
         if (date("YmdHis", $advnotice_time) <= date("YmdHis")) {
             $recipients = $this->get_all_recipients();
             $subject = sprintf("Adv Notice: %s", $this->get_value('reminderSubject'));
             $content = $this->get_value('reminderContent');
             foreach ($recipients as $person) {
                 if ($person['emailAddress']) {
                     $email = sprintf("%s %s <%s>", $person['firstName'], $person['surname'], $person['emailAddress']);
                     $e = new email_send($email, $subject, $content, "reminder_advnotice");
                     $e->send();
                 }
             }
             $this->set_value('reminderAdvNoticeSent', 1);
             $this->save();
         }
     }
 }