2022-02-04 08:46:44 +00:00
< ? php
2022-05-17 08:52:56 +00:00
namespace Mail2Deck ;
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 ) {
$data = explode ( " : " , $info );
if ( count ( $data ) == 2 && ! isset ( $head [ $data [ 0 ]])) {
if ( trim ( $data [ 0 ]) === 'X-Original-To' ) {
$headerInfo -> { 'X-Original-To' } = trim ( $data [ 1 ]);
break ;
}
}
}
return $headerInfo ;
2022-02-04 08:46:44 +00:00
}
2022-02-08 11:34:16 +00:00
public function reply ( $sender , $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
$headers = array (
2022-02-08 13:06:13 +00:00
'From' => 'no-reply@' . $server ,
2022-02-04 12:57:16 +00:00
'MIME-Version' => '1.0' ,
'Content-Type' => 'text/html'
);
2022-02-08 11:34:16 +00:00
if ( $response ) {
2022-05-17 08:52:56 +00:00
$body = " <h1>A new card has been created on board <a href= \" " . NC_SERVER . " /index.php/apps/deck/#/board/ { $response -> board } " . " \" > { $response -> boardTitle } </a>.</h1>
< p > Check out this < a href = \ " " . NC_SERVER . " /index.php/apps/deck/#/board/ { $response -> board } /card/ { $response -> id } " . " \" >link</a> to see the newly created card.</p>
2022-05-12 09:07:34 +00:00
< p > Card ID is { $response -> id } </ p > " ;
$subject = 'A new card has been created!' ;
2022-02-08 11:34:16 +00:00
} else {
2022-05-12 09:07:34 +00:00
$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
}
2022-02-04 12:57:16 +00:00
$message = " <html> " ;
2022-05-12 09:07:34 +00:00
$message .= " <head><title>mail2deck response</title></head> " ;
2022-02-08 11:34:16 +00:00
$message .= " <body> $body </body> " ;
2022-02-04 12:57:16 +00:00
$message .= " </html> " ;
2022-02-08 11:34:16 +00:00
mail ( $sender , $subject , $message , $headers );
2022-02-04 08:46:44 +00:00
}
2022-05-17 08:52:56 +00:00
/**
* Deletes a mail
*
* @ param $email email id that you want to delete
*
* @ return void
*/
public function delete ( int $email )
{
imap_delete ( $this -> inbox , $email );
imap_expunge ( $this -> inbox );
}
2022-02-04 14:41:37 +00:00
}