2022-02-04 08:46:44 +00:00
< ? php
2022-05-17 08:52:56 +00:00
namespace Mail2Deck ;
2025-01-16 12:12:47 +00:00
use PHPMailer\PHPMailer\PHPMailer ;
use PHPMailer\PHPMailer\Exception ;
require 'vendor/autoload.php' ;
2022-05-17 08:52:56 +00:00
2022-02-04 08:46:44 +00:00
class MailClass {
private $inbox ;
public function __construct ()
{
$this -> inbox = imap_open ( " { " . MAIL_SERVER . " : " . MAIL_SERVER_PORT . MAIL_SERVER_FLAGS . " }INBOX " , MAIL_USER , MAIL_PASSWORD )
or die ( " can't connect: " . imap_last_error ());
}
public function __destruct ()
{
imap_close ( $this -> inbox );
}
public function getNewMessages () {
return imap_search ( $this -> inbox , 'UNSEEN' );
}
public function fetchMessageStructure ( $email ) {
return imap_fetchstructure ( $this -> inbox , $email );
}
public function fetchMessageBody ( $email , $section ) {
return imap_fetchbody ( $this -> inbox , $email , $section );
}
public function headerInfo ( $email ) {
2022-04-13 10:31:54 +00:00
$headerInfo = imap_headerinfo ( $this -> inbox , $email );
$additionalHeaderInfo = imap_fetchheader ( $this -> inbox , $email );
$infos = explode ( " \n " , $additionalHeaderInfo );
foreach ( $infos as $info ) {
2025-01-16 12:12:47 +00:00
$data = explode ( " : " , $info , 2 );
2022-04-13 10:31:54 +00:00
if ( count ( $data ) == 2 && ! isset ( $head [ $data [ 0 ]])) {
if ( trim ( $data [ 0 ]) === 'X-Original-To' ) {
$headerInfo -> { 'X-Original-To' } = trim ( $data [ 1 ]);
2025-01-16 12:12:47 +00:00
// break;
} else if ( trim ( $data [ 0 ]) === 'Message-ID' ) {
$headerInfo -> { 'Message-ID' } = trim ( $data [ 1 ]);
} else if ( trim ( $data [ 0 ]) === 'In-Reply-To' ) {
$headerInfo -> { 'In-Reply-To' } = trim ( $data [ 1 ]);
2022-04-13 10:31:54 +00:00
}
}
}
return $headerInfo ;
2022-02-04 08:46:44 +00:00
}
2025-02-13 14:59:06 +00:00
public function reply ( $sender , $sendername , $response = null ) {
2022-02-08 13:06:13 +00:00
$server = NC_SERVER ;
2022-02-10 14:24:29 +00:00
if ( strstr ( $server , " https:// " )) {
2022-02-08 13:06:13 +00:00
$server = str_replace ( 'https://' , '' , $server );
2022-02-10 14:24:29 +00:00
} else if ( strstr ( $server , " http:// " )) {
2022-02-08 13:06:13 +00:00
$server = str_replace ( 'http://' , '' , $server );
}
2022-02-04 12:57:16 +00:00
2025-01-16 12:12:47 +00:00
$mail = new PHPMailer ( true );
try {
$mail -> isSMTP ();
$mail -> Host = MAIL_SERVER ;
$mail -> SMTPAuth = true ;
$mail -> Username = MAIL_USER ;
$mail -> Password = MAIL_PASSWORD ;
$mail -> SMTPSecure = PHPMailer :: ENCRYPTION_STARTTLS ;
$mail -> Port = MAIL_SERVER_SMTPPORT ;
$mail -> setFrom ( MAIL_USER , 'Mail2Deck Notification' );
$mail -> isHTML ( true );
$mail -> SMTPOptions = [
'ssl' => [
'verify_peer' => false ,
'verify_peer_name' => false ,
'allow_self_signed' => true ,
],
];
if ( $response ) {
2025-01-29 12:24:26 +00:00
$body = " <p>We received your request and opened a support ticket. You can see it here: <a href= \" " . NC_SERVER . " /index.php/apps/deck/board/ { $response -> board } /card/ { $response -> id } " . " \" >Newroco Support</a>.</p> "
2025-01-16 12:12:47 +00:00
. " <p>To access the card, you will be asked to login, please use your company usual account details.</p> "
. " <p>Please add more details or respond to any comments from our team, so we can address the issue as fast as possible.</p><br><br> "
. " <p>Thank you for reaching out.</p><br> "
. " <span class='name' style='font-weight: bold; padding-right: 5px;'>Newroco</span> "
. " <span class='positionSeparator' style='color: #000; font-size: 15pt; line-height: 13px; width: 10px;'>|</span> "
. " <span class='position' style='font-weight: normal; padding-left: 5px;'>Support Team</span><br> "
. " <a href='https://newro.co' target='_blank' style='color: #00aeef; text-decoration: none;'> "
. " <img src='https://newro.co/logo.png' width='200' height='23' alt='newroco' style='margin: 0; padding: 0;'> "
. " </a><br><br> " ;
$subject = 'We received your support request' ;
} else {
$body = " <h1>There was a problem creating a new card.</h1><p>Make sure the board was setup correctly.</p> " ;
$subject = " A new card could not be created! " ;
}
2022-02-08 11:34:16 +00:00
2025-02-13 14:59:06 +00:00
//Inline image
$description = $response -> description ;
$pattern = '/\[(.*?)\]\((https?:\/\/.*\.(?:jpg|jpeg|png|gif))\)/i' ;
if ( preg_match ( $pattern , $description )) {
$descriptionFormatted = preg_replace ( '/\[(.*?)\]\((.*?)\)/' , '<img src="$2" alt="$1">' , $description );
} else {
2025-02-25 10:00:42 +00:00
$descriptionFormatted = preg_replace ( '/\[(.*?)\]\((.*?)\)/' , '<a href="$2" target="_blank">$1</a>' , $description );
2025-02-13 14:59:06 +00:00
}
2025-01-29 12:24:26 +00:00
$bodySupport = " <p><a href= \" " . NC_SERVER . " /index.php/apps/deck/board/ { $response -> board } /card/ { $response -> id } " . " \" > { $response -> title } </a></p> "
2025-02-13 14:59:06 +00:00
. " <p> { $descriptionFormatted } </p> "
2025-01-23 09:40:46 +00:00
. " <p>Sent by: { $sender } </p> " ;
2025-01-16 12:12:47 +00:00
/**
* EMAIL 1 : email to sender
*/
$mail -> addAddress ( $sender );
$mail -> Subject = $subject ;
$mail -> Body = " <html> "
. " <head><title>mail2deck response</title></head> "
. " <body> $body </body> "
. " </html> " ;
$mail -> send ();
echo " Mail sent successfully to $sender . " ;
if ( MAIL_SUPPORT != '' ){
// Clean recipients and attachments for the next email
$mail -> clearAddresses ();
$mail -> clearAttachments ();
/**
* EMAIL 2 : email to support team
*/
$mail -> addAddress ( MAIL_SUPPORT );
2025-02-13 14:59:06 +00:00
$mail -> addReplyTo ( $sender , $sendername );
2025-01-16 12:12:47 +00:00
$mail -> Subject = " New Card Issue Notification " ;
$mail -> Body = " <html> "
. " <head><title>mail2deck response</title></head> "
. " <body> $bodySupport </body> "
. " </html> " ;
$mail -> send ();
echo " Mail sent successfully to support team. " ;
}
} catch ( Exception $e ) {
echo " Mail could not be sent. PHPMailer Error: { $mail -> ErrorInfo } " ;
}
2022-02-04 12:57:16 +00:00
2022-02-04 08:46:44 +00:00
}
2022-05-17 08:52:56 +00:00
/**
2022-05-19 08:16:03 +00:00
* Mark emails for deletion
2025-01-16 12:12:47 +00:00
*
2022-05-19 08:16:03 +00:00
* @ param $email email number that you want to delete
2025-01-16 12:12:47 +00:00
*
2022-05-17 08:52:56 +00:00
* @ return void
*/
public function delete ( int $email )
{
2022-05-19 08:16:03 +00:00
imap_delete ( $this -> inbox , imap_uid ( $this -> inbox , $email ), FT_UID );
}
/**
* Delete all messages marked for deletion
*/
public function expunge ()
{
2022-05-17 08:52:56 +00:00
imap_expunge ( $this -> inbox );
}
2022-02-04 14:41:37 +00:00
}