Moritz Schmidt 10 anos atrás
pai
commit
75a2b5fd72
5 arquivos alterados com 90 adições e 1 exclusões
  1. 23 0
      ajax.php
  2. 27 0
      includes/mail.inc.php
  3. 27 0
      includes/mailboxfolder.inc.php
  4. 12 0
      scripts/custom.js
  5. 1 1
      templates/maillist.php

+ 23 - 0
ajax.php

@@ -12,6 +12,7 @@ require('includes/mailboxfolder.inc.php');
 require('includes/documenthandler.inc.php');
 require('includes/call.inc.php');
 require('includes/reminder.inc.php');
+require('includes/mail.inc.php');
 
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 
@@ -331,6 +332,28 @@ switch($_REQUEST['action']) {
         $return['status'] = "OK";
         echo json_encode($return);
         break;
+    case 'getMailContent':
+        header("Status: 200 OK");
+
+        $mail = Mail::getMailByMailID($_REQUEST['mailID']);
+        $mailboxFolder = Mailboxfolder::getMailboxfolderByID($mail->getMailboxFolderID());
+        $mailbox = Mailbox::getMailboxById($mailboxFolder->getMailboxId(), true);
+
+        $mailbox->changeFolder($mailboxFolder->getFolderName());
+        $bodyLines =  explode(PHP_EOL, imap_fetchbody($mailbox->getMailbox(), $mail->getMailUID(), 1));
+        $body = "%0D%0A"; // newline on top
+
+        foreach($bodyLines as $line) {
+            $body .= ">" . $line . '%0D%0A';
+        }
+
+        $return = array(
+            "to"        => $mail->getMailSender(),
+            "subject"   => $mail->getSubject(),
+            "body"      => $body
+        );
+
+        echo json_encode($return);
     case 'debugTest': // for testing single methods etc.
 
         break;

+ 27 - 0
includes/mail.inc.php

@@ -165,6 +165,33 @@ class Mail {
          echo "<br><br>";
      }
 
+     /**
+     * Get Mail by Mail-ID
+     *
+     * @param int $mailID  ID of Mail
+     *
+     * @return Mail
+     *
+     */
+
+     public static function getMailByMailID($mailID) {
+         global $db;
+
+         $mails = $db->selectQuery("SELECT * FROM `mails` WHERE `id` = " . $mailID . ";");
+
+         $return = array();
+
+         if(!$mails) {
+             return false;
+         }
+
+         foreach($mails as $mail) {
+             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
+         }
+
+         return $return[0];
+     }
+
      /**
      * Get Mail by Mail information
      *

+ 27 - 0
includes/mailboxfolder.inc.php

@@ -30,6 +30,33 @@ class MailboxFolder {
         return $this->labelId;
     }
 
+    /**
+     * Get MailboxFolder by Folder-ID
+     *
+     *
+     * @param string $folderID  ID of folder
+     *
+     * @return MailboxFolder  Selected MailboxFolder
+     *
+     */
+
+    public static function getMailboxFolderByID($folderID) {
+        global $db;
+
+        $return = array();
+        $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `id` = '" . $folderID . "';");
+
+        if(!$folders) {
+            return false;
+        }
+
+        foreach($folders as $folder) {
+            $return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
+        }
+
+        return $return[0];
+    }
+
     /**
      * Get MailboxFolder by Folder-name
      *

+ 12 - 0
scripts/custom.js

@@ -353,6 +353,18 @@ $(document).ready(function() {
                 }
             });
         });
+
+        $(document).on("click", ".reply-mail", function(e) {
+            e.preventDefault();
+
+            data = {
+                mailID: $(this).attr("data-mail-id")
+            };
+
+            $.getJSON("ajax.php?action=getMailContent", data, function(r) {
+                window.location.href = "mailto:" + r['to'] + "?subject=" + r['subject'] + "&body=" + r['body'];
+            });
+        });
     }
 
     function reloadDraftVars() {

+ 1 - 1
templates/maillist.php

@@ -14,7 +14,7 @@ foreach($this->_['mails'] as $mail) {
     echo '<td>' . $mail->getMailSender() . '</td>';
     echo '<td>' . $mail->getMailRecipient() . '</td>';
     echo '<td>' . $mail->getSubject() . '</td>';
-    echo '<td></td>';
+    echo '<td><a href="#" data-mail-id="' . $mail->getID() . '" class="reply-mail"><i class="fa fa-reply"></i></a></td>';
     echo '</tr>';
 }
 ?>