2022-02-04 08:46:44 +00:00
< ? php
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 ) {
return imap_headerinfo ( $this -> inbox , $email );
}
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 ;
if ( str_contains ( $server , " https:// " )) {
$server = str_replace ( 'https://' , '' , $server );
} else if ( str_contains ( $server , " http:// " )) {
$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 ) {
$body = " <h1>You created a new issue on board { $response -> boardTitle } .</h1><p>Check out this <a href= \" " . NC_SERVER . " /index.php/apps/deck/#/board/ { $response -> board } /card/ { $response -> id } " . " \" >link</a> to see your newly created card.</p> " ;
$subject = 'An issue has been reported!' ;
} else {
$body = " <h1>There was a problem creating your new card.</h1><p>Make sure you set up the board correctly.</p> " ;
$subject = " Your issue has not been reported! " ;
}
2022-02-04 12:57:16 +00:00
$message = " <html> " ;
2022-02-08 11:34:16 +00:00
$message .= " <head><title>Mail2Deck response</title></head> " ;
$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-02-04 14:41:37 +00:00
}