コード例 #1
0
ファイル: mail.php プロジェクト: alerque/bibledit
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Database_Mail();
     }
     return self::$instance;
 }
コード例 #2
0
ファイル: mailTest.php プロジェクト: alerque/bibledit
 public function testNormalPostpone()
 {
     $database_mail = Database_Mail::getInstance();
     $session_logic = Session_Logic::getInstance();
     $session_logic->setUsername("phpunit");
     $database_mail->send("phpunit", "subject", "body");
     $mails = $database_mail->getMailsToSend();
     $this->assertEquals(1, count($mails));
     $database_mail->postpone(1);
     $mails = $database_mail->getMailsToSend();
     $this->assertEquals(0, count($mails));
 }
コード例 #3
0
ファイル: mailer.php プロジェクト: alerque/bibledit
/**
* Sends email $id
*/
function sendMail($id)
{
    // The databases involved.
    $database_mail = Database_Mail::getInstance();
    $database_log = Database_Logs::getInstance();
    $database_users = Database_Users::getInstance();
    // Get all details of the mail.
    $details = $database_mail->get($id);
    $username = $details['username'];
    $email = $database_users->getUserToEmail($username);
    $subject = $details['subject'];
    $body = $details['body'];
    // Bail out when username was empty.
    if ($username == "") {
        return;
    }
    // If this username was not found, it could be that the email was addressed to a non-user,
    // and that the To: address was actually contained in the $username.
    if ($email == "") {
        $email = $username;
        $username = "";
    }
    // If the email address validates, ok, else remove this mail from the queue and log the action.
    $validator = new Zend_Validate_EmailAddress();
    if (!$validator->isValid($email)) {
        $database_mail->delete($id);
        $message = "Email to {$email} was deleted because of an invalid email address";
        $database_log->log($message);
        return;
    }
    // Send the email.
    try {
        $mail = new Mail_Send($email, $username, $subject, $body);
        unset($mail);
        $database_mail->delete($id);
        $message = "Email to {$email} with subject {$subject} was sent successfully";
        $database_log->log($message, Filter_Roles::MANAGER_LEVEL);
    } catch (Exception $e) {
        $database_mail->postpone($id);
        $message = $e->getMessage();
        $message = "Email to {$email} could not be sent - reason: {$message}";
        $database_log->log($message);
    }
}
コード例 #4
0
ファイル: worker.php プロジェクト: alerque/bibledit
 /**
  * handleEmail - handles a confirmation email received from $from with subject $subject and body $body.
  * Returns true if the mail was handled, else false.
  */
 public function handleEmail($from, $subject, $body)
 {
     // Find out in the confirmation database whether the $subject line contains an active ID.
     // If not, bail out.
     $database_confirm = Database_Confirm::getInstance();
     $id = $database_confirm->searchID($subject);
     if ($id == 0) {
         return false;
     }
     // An active ID was found: Execute the associated database query.
     $query = $database_confirm->getQuery($id);
     $database_users = Database_Users::getInstance();
     Database_SQLite::exec($database_users->db, $query);
     // Send confirmation mail.
     $mailto = $database_confirm->getMailTo($id);
     $subject = $database_confirm->getSubject($id);
     $body = $database_confirm->getBody($id);
     $database_mail = Database_Mail::getInstance();
     $database_mail->send($mailto, $subject, $body);
     // Delete the confirmation record.
     $database_confirm->delete($id);
     // Job done.
     return true;
 }
コード例 #5
0
ファイル: bibles.php プロジェクト: alerque/bibledit
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
$database_users = Database_Users::getInstance();
$database_logs = Database_Logs::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_books = Database_Books::getInstance();
$session_logic = Session_Logic::getInstance();
$database_mail = Database_Mail::getInstance();
@($username = Filter_Hex::hex2bin($_POST['u']));
@($password = $_POST['p']);
@($bible = $_POST['b']);
@($book = $_POST['bk']);
@($chapter = $_POST['c']);
$action = $_POST['a'];
if ($action == "total") {
    // The server reads the credentials from the client's user,
    // checks which Bibles this user has access to,
    // calculate the checksum of all chapters in those Bibles,
    // and returns this checksum to the client.
    $user_ok = $database_users->usernameExists($username);
    if (!$user_ok) {
        $database_logs->log("Non existing user {$username}", Filter_Roles::MANAGER_LEVEL);
    }
コード例 #6
0
ファイル: logic.php プロジェクト: alerque/bibledit
 /**
  * handleEmailNew - handles an email received from $from with subject $subject and body $body.
  * Returns true if the mail was processed, else false.
  * The email is considered to have been processed if it created a new Consultation Note.
  */
 public function handleEmailNew($from, $subject, $body)
 {
     // Store the original subject.
     $originalSubject = $subject;
     // Check that the subject indicates that a new consultation note is to be created.
     $pos = strpos(strtolower($subject), "new note");
     if ($pos === false) {
         return false;
     }
     // There is a new note. Remove that bit from the $subject.
     $subject = substr($subject, 0, $pos) . substr($subject, $pos + 8);
     // Clean the subject line.
     $subject = trim($subject);
     $subject = str_replace(".", " ", $subject);
     $subject = str_replace(":", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     // Check that the $from address of the email belongs to an existing user.
     $from = Filter_Email::extractEmail($from);
     $database_users = Database_Users::getInstance();
     if (!$database_users->emailExists($from)) {
         return false;
     }
     $username = $database_users->getEmailToUser($from);
     // Extract book, chapter, verse, and note summary from the $subject
     $book = NULL;
     $chapter = NULL;
     $verse = NULL;
     $summary = NULL;
     $subject = explode(" ", $subject);
     if (count($subject) > 0) {
         $book = Filter_Books::interpretBook($subject[0]);
     }
     if (count($subject) > 1) {
         $chapter = Filter_Numeric::integer_in_string($subject[1]);
     }
     if (count($subject) > 2) {
         $verse = Filter_Numeric::integer_in_string($subject[2]);
     }
     unset($subject[0]);
     unset($subject[1]);
     unset($subject[2]);
     $summary = implode(" ", $subject);
     unset($subject);
     // Check book, chapter, verse, and summary. Give feedback if there's anything wrong.
     $noteCheck = "";
     if (!(is_numeric($book) && $book > 0)) {
         $noteCheck .= Locale_Translate::_("Unknown book");
     }
     if (!is_numeric($chapter)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown chapter");
     }
     if (!is_numeric($verse)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown verse");
     }
     if ($summary == NULL || $summary == "") {
         $noteCheck .= " " . Locale_Translate::_("Unknown summary");
     }
     // Mail user if the note could not be posted.
     $database_mail = Database_Mail::getInstance();
     if ($noteCheck != "") {
         $subject = Locale_Translate::_("Your new note could not be posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $noteCheck);
         return false;
     }
     // Clean the email's body.
     $body = Filter_Email::extractBody($body);
     // Post the note.
     $session_logic = Session_Logic::getInstance();
     $sessionuser = $session_logic->currentUser();
     $session_logic->setUsername($username);
     $database_notes = Database_Notes::getInstance();
     $identifier = $database_notes->storeNewNote("", $book, $chapter, $verse, $summary, $body, false);
     $this->handlerNewNote($identifier);
     $session_logic->setUsername($sessionuser);
     // Mail confirmation to the $username.
     $database_config_user = Database_Config_User::getInstance();
     if ($database_config_user->getUserNotifyMeOfMyPosts($username)) {
         $subject = Locale_Translate::_("Your new note was posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $body);
     }
     // Log operation.
     $database_logs = Database_Logs::getInstance();
     $database_logs->log("New note posted" . ":" . " " . $body);
     // Job done.
     return true;
 }