Seite 1 von 1

Bei Email-Eingang Script starten

Verfasst: 09.05.2006, 09:39
von mcchaos
Hallo! Gibt es eine Möglichkeit, in einem Hosting-Paket (Apache/Sendmail/Confixx) ein PHP-Script zu starten, wenn eine Email an eine bestimmte Adresse gesendet wird? Mir fällt nix ein, aber vielleicht geht es ja doch irgendwie.

Verfasst:
von
Content Erstellung von ABAKUS Internet Marketing
Ihre Vorteile:
  • einzigartige Texte
  • suchmaschinenoptimierte Inhalte
  • eine sinnvolle Content-Strategie
  • Beratung und Umsetzung
Jetzt anfragen: 0511 / 300325-0

Verfasst: 09.05.2006, 10:43
von Fantomas
Hi,

das kannst Du über die /etc/aliases (je nach Distro) einstellen:

Code: Alles auswählen

user: "|/path/to/script.pl"
Alternativ per Cron regelmäßig das Postfach abfragen.

F.

Verfasst: 09.05.2006, 10:45
von mcchaos
Hi Fantomas,

danke für Die Antwort. Ja an Cronjob dachte ich auch schon. Ist halt nicht so schön ;-)

Bin leider kein Linux-Freak: Wie würde die andere Lösung funktionieren? Wie gesagt, ich habe nur ein Hosting-Paket und denke, dass ich auf /etc/aliases gar nicht zugreifen kann...

Verfasst:
von

Verfasst: 09.05.2006, 11:25
von Fantomas
mcchaos hat geschrieben:danke für Die Antwort. Ja an Cronjob dachte ich auch schon. Ist halt nicht so schön ;-)
Warum?
mcchaos hat geschrieben: Bin leider kein Linux-Freak: Wie würde die andere Lösung funktionieren? Wie gesagt, ich habe nur ein Hosting-Paket und denke, dass ich auf /etc/aliases gar nicht zugreifen kann...
Frag Deinen Hoster, nur der kann es wissen ;)

F.

Verfasst: 09.05.2006, 11:33
von mcchaos
Fantomas hat geschrieben:
mcchaos hat geschrieben:danke für Die Antwort. Ja an Cronjob dachte ich auch schon. Ist halt nicht so schön ;-)
Warum?
Naja, weil Du 1. immer eine Latenzzeit hast (wenn Du das Script nicht gerade jede Minute laufen läßt) und 2. natürlich die Serverlast evtl. unnötig erhöhst (obwohl mir das natürlich beim Hosting prinzipiell egal sein kann).
Fantomas hat geschrieben:
mcchaos hat geschrieben: Bin leider kein Linux-Freak: Wie würde die andere Lösung funktionieren? Wie gesagt, ich habe nur ein Hosting-Paket und denke, dass ich auf /etc/aliases gar nicht zugreifen kann...
Frag Deinen Hoster, nur der kann es wissen ;)

F.
Klar ;-) Ich habe bei diesem Paket nur nen FTP-Zugriff, und da gibt's kein /etc/aliases. Und ich vermute mal, dass man es nicht wie bei der .htaccess einfach in ein Verzeichnis knallen kann.

Verfasst: 09.05.2006, 11:46
von Fantomas
Latenzzeit ist klar - 10 Minuten kann sehr viel sein :)
Last sehe ich nicht als Problem - Anmelden am Pop-Konto, Mails checken, fertig, Genau das Selbe mach dein Mailprogramm.

Verfasst: 09.05.2006, 12:03
von mcchaos
Danke für die Antworten! Dann werde ich mir mal POP3 zu Gemüte führen :wink:

Verfasst: 09.05.2006, 21:56
von Outman
mcchaos hat geschrieben:Danke für die Antworten! Dann werde ich mir mal POP3 zu Gemüte führen :wink:
Hiho,

ich habe hier noch ein schönes kleines Script gefunden was den Pop3 Abfrägt und die Daten in eine Db speichert. Die Db musst Du dir aber selber erstellen.

Hier der Code:

Code: Alles auswählen

<html>
<head>
<style type="text/css"> 
<!-- 
.style &#123; 
    font-size&#58; 14px; 
    font-family&#58; Arial, Helvetica, sans-serif; 
&#125; 
--> 
</style> 
</head>
<body>
<table width="100%"  border="0" cellspacing="10" cellpadding="0"> 
  <tr> 
    <td><span class="style"> 
<?php 
$time = microtime&#40;&#41;; 
$time = explode&#40;' ', $time&#41;; 
$time = $time&#91;1&#93; + $time&#91;0&#93;; 
$start = $time; 

// ---------------------------------------------------------------------------- // 
// Script config 

$my_config 									= array&#40;&#41;; // Configuration Parameters 
$my_mail 									= array&#40;&#41;; // Mail parameters for each mail looped 
$my_master 									= array&#40;&#41;; // Script master variables 

$my_config&#91;'debug'&#93; 						= TRUE; 

$my_config&#91;'sendmail'&#93; 						= FALSE;       	// Schickt Sie die Anzeige zu den gegebenen adress - > verwendet zu
$my_config&#91;'sendmail_to'&#93; 					= ''; 
$my_config&#91;'display_content'&#93; 				= FALSE;        // !! Aktivieren Sie nicht, wenn Briefkasten eine Menge Anzeigen als er enthält
                                                        	// verlangsamt hinunter den Prozeß ziemlich schwer
$my_config&#91;'delete_mail'&#93; 					= TRUE;        	// Löschungpost vom Bediener nach analysieren
$my_config&#91;'move_mail'&#93; 					= '';         	// wenn anders als "", Post auf gegebenes Heft verschoben werden
$my_config&#91;'writetoDB'&#93; 					= TRUE;        	// Speichern Sie Post in der SQL-Datenbank
$my_config&#91;'folder'&#93; 						= 'inbox';	    // Verwendet für SQL-Tabelle, Feld "folder" 
$my_config&#91;'save_attachments'&#93; 				= TRUE; 
$my_config&#91;'send_invalidattach_mail'&#93; 		= TRUE;         // Wenn unzulässig, antworten die gefundenen Zubehöre, auf Absender

$my_config&#91;'sql'&#93;&#91;'host'&#93; =                 "localhost"; 
$my_config&#91;'sql'&#93;&#91;'user'&#93; =                 "web1"; 
$my_config&#91;'sql'&#93;&#91;'pass'&#93; =                 ""; 
$my_config&#91;'sql'&#93;&#91;'db'&#93; =                   ""; 

$my_config&#91;'IMAP'&#93;&#91;'host'&#93; =                 "&#123;localhost/pop3&#58;110&#125;"; 
$my_config&#91;'IMAP'&#93;&#91;'user'&#93; =                 "web1p2"; 
$my_config&#91;'IMAP'&#93;&#91;'pass'&#93; =                 ""; 
$my_config&#91;'IMAP'&#93;&#91;'folder'&#93; =               "INBOX"; 

// ---------------------------------------------------------------------------- // 
// Connect to DB and IMAP 
if &#40;!@$dbh=mysql_connect &#40;$my_config&#91;'sql'&#93;&#91;'host'&#93;, $my_config&#91;'sql'&#93;&#91;'user'&#93;, $my_config&#91;'sql'&#93;&#91;'pass'&#93;&#41;&#41; &#123; 
    debug&#40;"mySQL connection failed"&#41;; 
    exit; 
&#125; else &#123; 
    mysql_select_db &#40;$my_config&#91;'sql'&#93;&#91;'db'&#93;,$dbh&#41;; 
    $run_query = mysql_query&#40;"UPDATE runs SET last=NOW&#40;&#41; WHERE id=1",$dbh&#41;; 
    debug&#40;"mySQL OK"&#41;; 
&#125; 

$imapconnect = $my_config&#91;'IMAP'&#93;&#91;'host'&#93;.$my_config&#91;'IMAP'&#93;&#91;'folder'&#93;; 
if &#40;!@$imapmailbox = imap_open &#40;$imapconnect, $my_config&#91;'IMAP'&#93;&#91;'user'&#93;, $my_config&#91;'IMAP'&#93;&#91;'pass'&#93;&#41;&#41; &#123; 
    debug&#40;"IMAP connection failed"&#41;; 
    exit; 
&#125; 

else &#123; debug&#40;"IMAP OK"&#41;; &#125; 
// ---------------------------------------------------------------------------- // 

// Number of messages 
$imapcheck = imap_check&#40;$imapmailbox&#41;; 
$my_master&#91;'Nmsgs'&#93; = $imapcheck->Nmsgs; 
debug&#40;" ".$my_master&#91;'Nmsgs'&#93;." messages in $imapconnect<br><hr size="3" noshade>"&#41;; debug&#40;''&#41;; 


// ---------------------------------------------------------------------------- // 
// ---------------------------------------------------------------------------- // 
// Begin Mail Loop 
$my_master&#91;'loopindex'&#93; = 1; 
$mailsdeleted=0; 



while &#40;$my_master&#91;'loopindex'&#93; <= $my_master&#91;'Nmsgs'&#93;&#41; &#123; 
     
    debug&#40;"<br><b>Analyzing message nr. ".$my_master&#91;'loopindex'&#93;." <br>-------------------------------------------------<br></b>"&#41;; 

    // ---------------------------------------------------------------------------- // 
    //get mail headers and structure 
    $header = imap_headerinfo&#40;$imapmailbox, $my_master&#91;'loopindex'&#93;,250,250&#41;; 
    $structure = imap_fetchstructure&#40;$imapmailbox, $my_master&#91;'loopindex'&#93;&#41;; 
     
    $my_mail&#91;'type'&#93; = $structure->type; // Mail type &#40;0=TEXT 1=MULTIPART&#41; 
    $my_mail&#91;'tcode'&#93; = $structure->encoding; // Mail encoding 
     
    // ---------------------------------------------------------------------------- // 
    //extract header information 
    $date = $header->udate; // -> UNIX TIMESTAMP 
    $my_mail&#91;'date'&#93; = date&#40;"Y/m/d H&#58;i",$date&#41;; 
     
    $from_email_mailbox = $header->from&#91;0&#93;->mailbox; // jack 
    $from_email_host = $header->from&#91;0&#93;->host; // something.com 
    $my_mail&#91;'from'&#93;&#91;'email'&#93; = $from_email_mailbox."@".$from_email_host; // jack@something.com 
    $my_mail&#91;'from'&#93;&#91;'name'&#93; = $header->from&#91;0&#93;->personal; // JACK SOMETHING 

    $to_email_mailbox = $header->to&#91;0&#93;->mailbox; 
    $to_email_host = $header->to&#91;0&#93;->host; 
    $my_mail&#91;'to'&#93;&#91;'email'&#93; = $to_email_mailbox."@".$to_email_host; 
    $my_mail&#91;'to'&#93;&#91;'name'&#93; = $header->to&#91;0&#93;->personal; 
     
    $replyto_email_mailbox = $header->reply_to&#91;0&#93;->mailbox; 
    $replyto_email_host = $header->reply_to&#91;0&#93;->host; 
    $my_mail&#91;'replyto'&#93;&#91;'email'&#93; = $replyto_email_mailbox."@".$replyto_email_host; 
    $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = $header->reply_to&#91;0&#93;->personal; 
     
    $my_mail&#91;'cc'&#93; = $header->ccaddress; // multiple CC's resp. BCC's possible 
    $my_mail&#91;'bcc'&#93; = $header->bccaddress; // multiple CC's resp. BCC's possible 
     
    $my_mail &#91;'subject'&#93; = $header->fetchsubject; 
     
    // ---------------------------------------------------------------------------- // 
    // Decode header elements 
    $my_mail&#91;'from'&#93;&#91;'name'&#93; = utf8_decode&#40;imap_utf8&#40;$my_mail&#91;'from'&#93;&#91;'name'&#93;&#41;&#41;; 
    $my_mail&#91;'to'&#93;&#91;'name'&#93; = utf8_decode&#40;imap_utf8&#40;$my_mail&#91;'to'&#93;&#91;'name'&#93;&#41;&#41;; 
    $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = utf8_decode&#40;imap_utf8&#40;$my_mail&#91;'replyto'&#93;&#91;'name'&#93;&#41;&#41;; 
    $my_mail&#91;'subject'&#93; = utf8_decode&#40;imap_utf8&#40;$my_mail&#91;'subject'&#93;&#41;&#41;; 
    $my_mail&#91;'subject'&#93; = quoted_printable_decode&#40;$my_mail&#91;'subject'&#93;&#41;; 
     
    // ---------------------------------------------------------------------------- // 
    // Extract and decode mailtext & attachment&#40;s&#41; 
    // TYPE 0 MAIL &#40;plain&#41; 
    if &#40;$my_mail&#91;'type'&#93; == 0&#41; &#123; 
         
        // Get mail body 
        $mailtext = imap_body&#40;$imapmailbox, $my_master&#91;'loopindex'&#93;&#41;; 
                 
        if &#40;$my_mail&#91;'tcode'&#93; == 3&#41; &#123; 
              $mailtext = base64_decode&#40;$mailtext&#41;; 
        &#125; else &#123; 
             $mailtext = quoted_printable_decode&#40;$mailtext&#41;; 
        &#125; 
         
        $my_mail&#91;'body'&#93; = $mailtext; 
    &#125; 
     
    // TYPE 1 MAIL &#40;multipart&#41; 
    if &#40;$my_mail&#91;'type'&#93; == 1&#41; &#123; 
         
           $struct = $structure; 
           $mbox = $imapmailbox; 
           $mid = $my_master&#91;'loopindex'&#93;; 
           $parts = $struct->parts; 
           $i = 0; 
           $endwhile = false; 
       
           $stack = array&#40;&#41;; // Stack while parsing message 
           $content = "";    // Message content 
           $my_mail&#91;'attachment'&#93; = array&#40;&#41;; // Attachments 
       
           while &#40;!$endwhile&#41; &#123; 
               if &#40;!$parts&#91;$i&#93;&#41; &#123; 
                   if &#40;count&#40;$stack&#41; > 0&#41; &#123; 
                       $parts = $stack&#91;count&#40;$stack&#41;-1&#93;&#91;"p"&#93;; 
                       $i    = $stack&#91;count&#40;$stack&#41;-1&#93;&#91;"i"&#93; + 1; 
                       array_pop&#40;$stack&#41;; 
                   &#125; else &#123; 
                       $endwhile = true; 
                   &#125; 
               &#125; 
         
               if &#40;!$endwhile&#41; &#123; 
                // Get message part &#40;1.1.1 eg.&#41; 
                $partstring = ""; 
                foreach &#40;$stack as $s&#41; &#123; 
                    $partstring .= &#40;$s&#91;"i"&#93;+1&#41; . "."; 
                &#125; 
                $partstring .= &#40;$i+1&#41;; 
                if &#40;strtoupper&#40;$parts&#91;$i&#93;->disposition&#41; == "ATTACHMENT"&#41; &#123; // Part is attachment 
                    $my_mail&#91;'attachment'&#93;&#91;&#93; = array&#40;"filename" => $parts&#91;$i&#93;->parameters&#91;0&#93;->value,"filedata" => imap_fetchbody&#40;$mbox, $mid, $partstring&#41;&#41;; 
                &#125; elseif &#40;strtoupper&#40;$parts&#91;$i&#93;->subtype&#41; == "PLAIN"&#41; &#123; // Part is Message 
                    $content .= imap_fetchbody&#40;$mbox, $mid, $partstring&#41;; 
                &#125; 
            &#125; 
            if &#40;$parts&#91;$i&#93;->parts&#41; &#123; 
                $stack&#91;&#93; = array&#40;"p" => $parts, "i" => $i&#41;; 
                $parts = $parts&#91;$i&#93;->parts; 
                $i = 0; 
            &#125; else &#123; 
                $i++; 
            &#125; 
        &#125; 
        $my_mail&#91;'body'&#93; = $content; 
         
        // ---------------------------------------------------------------------------- // 
        // extract and save attachments, if any 
        $my_mail&#91;'nbattachs'&#93; = count&#40;$my_mail&#91;'attachment'&#93;&#41;; 
         
        if &#40;$my_mail&#91;'nbattachs'&#93; > 0&#41; &#123; 
             
            // attachments found 
            debug&#40;"Mail has ".$my_mail&#91;'nbattachs'&#93;." Attachments"&#41;; 
             
            //Definieren Sie Zubehörschleifenfunktionen
            $attach_invalid = 0; 
            $a = 0; 
            $str = ""; 
            $dirname = ""; 
             
            //create specific folders 
             
            $dirname = random&#40;&#41;; 
            $dirpath = "/home/www/web1/html/imap2sql/_attachments/".$dirname; 
             
            while&#40;is_dir&#40;"$dirpath"&#41;&#41; &#123; 
                $dirname = random&#40;&#41;; 
                $dirpath = "_attachments/".$dirname; 
            &#125; 
            if &#40;$my_config&#91;'save_attachments'&#93;&#41; &#123; 
                mkdir&#40;"$dirpath", 0777&#41;; 
                debug&#40;"&#40;Created folder => $dirname&#41;"&#41;; 
            &#125; else &#123; 
                debug&#40;"&#40;Folder not created&#58; save_attachments OFF&#41;"&#41;; 
            &#125; 
            // schlingen Sie Zubehöre, decodieren Sie und speichern Sie sie
            while &#40;$a <= $my_mail&#91;'nbattachs'&#93;-1&#41; &#123; 
                $filename = ""; 
                $filename = utf8_decode&#40;imap_utf8&#40;$my_mail&#91;'attachment'&#93;&#91;$a&#93;&#91;'filename'&#93;&#41;&#41;; 
                //$filename = quoted_printable_decode&#40;$my_mail&#91;'attachment'&#93;&#91;$a&#93;&#91;'filename'&#93;&#41;; 
                 
                debug&#40;"&#40;".$a ." => ".$filename." | ",0&#41;; 
                 
                // Überprüfen Sie, ob Zubehör gültig ist
                if &#40;!preg_match&#40;"=.jpg$|.gif$|.bmp$|.png$|.rar$|.zip$|.pdf$|.xls$|.doc$|.txt$|.htm$|.html$|.jpeg$=i",$filename&#41;&#41; &#123; 
                    // File Type is invalid 
                    debug&#40;"INVALID&#41;"&#41;; 
                    $attach_invalid++; 
                    $attachs_error_echo.= $filename."*"; 
                &#125; else &#123; 
                    // Aktenart ist, fortfahren gültig
                    debug&#40;"VALID&#41;  ",0&#41;; 
                     
                    // decode content 
                    if &#40;preg_match&#40;"=.txt$=i",$filename&#41;&#41; &#123; 
                        $input = $my_mail&#91;'attachment'&#93;&#91;$a&#93;&#91;'filedata'&#93;; 
                    &#125; else &#123; 
                        $input = base64_decode&#40;$my_mail&#91;'attachment'&#93;&#91;$a&#93;&#91;'filedata'&#93;&#41;; 
                    &#125; 
                     
                    // save content 
                    if &#40;$my_config&#91;'save_attachments'&#93;&#41; &#123; 
                        // check if filename exists in that directory and open handle 
						chmod &#40;$dirpath, 0777&#41; or die&#40;'Konnte die Rechte nicht ändern von&#58; <BR><i>' . $dirpath . '</i>'&#41; ;
                        $handle = fopen&#40;$dirpath."/".$filename, "w"&#41; or die&#40;'Konnte die Datei&#58; <BR><i>' . $filename . '</i> nicht anlegen!'&#41;; 
                        //if &#40;fwrite&#40;$handle, $input&#41;&#41; &#123; 
                        //    debug&#40;"Saved => ".$filename&#41;; 
                        //&#125; else &#123; 
                        //    debug&#40;"Save => ".$filename." failed!"&#41;; 
                        //&#125; 
						if &#40;!fwrite&#40;$handle, $input&#41;&#41; &#123;
							   print "Kann in die Datei $filename nicht schreiben";
							   exit;
						&#125;

						fclose&#40;$handle&#41;; 
                    &#125; else &#123; 
                        debug&#40;"save_attachments OFF"&#41;; 
                    &#125; 
                &#125; 
                $a++; 
            &#125; 

            // One or more Attachments were invalid 
            if &#40;$attach_invalid == $my_mail&#91;'nbattachs'&#93;&#41; &#123; 
                // None of the attach&#40;s&#41; valid -> delete folder 
                @rmdir&#40;$dirpath&#41;; 
                debug &#40;"NONE OF THE ATTACH&#40;S&#41; VALID -> $dirpath DELETED"&#41;; 
                unset&#40;$dirpath, $dirname&#41;; 
            &#125; 
            if&#40;$attachs_error_echo&#41;&#123; //  -> send notification mail to sender 
                $new_subject = "Re&#58; ".$my_mail&#91;'subject'&#93;; 
                $new_body = "Note that this is an automated message\n\n\nWe have received your email. However, one or more attachments were not accepted, since they violated the systems security issues&#58;\n\n$attachs_error_echo\n\nWith * marked files we had to decline.\n\n\n"; 
                 
                if &#40;$my_config&#91;'send_invalidattach_mail'&#93;&#41; &#123; 
                    mail&#40;$my_mail&#91;'from'&#93;&#91;'email'&#93;,$new_subject,$new_body,"From&#58; YOURNAME <box@host.com>\nReply-To&#58; YOURNAME <box@host.com>"&#41;; 
                    $insertDB = mysql_query&#40;"INSERT INTO `email` &#40; `id` , `date` , `type` , `encoding` , `folder` , `from_name` , `from_mail` , `to_name` , `to_mail` , `replyto_name` , `replyto_mail` , `subj` , `text` , `cc` , `dir` &#41; VALUES &#40;'' , 'NOW&#40;&#41;' , '0' , '0' , 'sent' , 'YOURNAME' , 'box@host.com' , '".$my_mail&#91;'from'&#93;&#91;'name'&#93;."' , '".$my_mail&#91;'from'&#93;&#91;'email'&#93;."' , '".$my_mail&#91;'from'&#93;&#91;'name'&#93;."' , '".$my_mail&#91;'from'&#93;&#91;'email'&#93;."' , '".$new_subject."' , '".$new_body."' , '' , '0'&#41;",$dbh&#41;; 

                    debug &#40;"INVALID ATTACH&#40;S&#41; MAIL SENT TO ".$my_mail&#91;'from'&#93;&#91;'email'&#93;.""&#41;; 
                &#125; else &#123; 
                    debug&#40;"Send invalid_attach_mail OFF"&#41;; 
                &#125; 
            &#125; 
         
        &#125; else &#123; 
            // no attachments found in email 
            debug&#40;"No attachments were found"&#41;; 
        &#125; 
         
        // decode mailtext 
        $my_mail&#91;'body'&#93; = quoted_printable_decode&#40;$my_mail&#91;'body'&#93;&#41;; 
        //$my_mail&#91;'body'&#93; = base64_decode&#40;$my_mail&#91;'body'&#93;&#41;; 
    &#125; 

    // ---------------------------------------------------------------------------- // 
    // ---------------------------------------------------------------------------- // 
    // do corrections -> cleaning up a little 
    // from 
    if &#40;$my_mail&#91;'from'&#93;&#91;'name'&#93; == ""&#41; &#123; 
        $my_mail&#91;'from'&#93;&#91;'name'&#93; = $my_mail&#91;'from'&#93;&#91;'email'&#93;; 
    &#125; 
    $my_mail&#91;'from'&#93;&#91;'name'&#93; = ereg_replace&#40;"'","",$my_mail&#91;'from'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'from'&#93;&#91;'name'&#93; = ereg_replace&#40;""","",$my_mail&#91;'from'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'from'&#93;&#91;'name'&#93; = addslashes&#40;$my_mail&#91;'from'&#93;&#91;'name'&#93;&#41;; 
     
    // To 
    if &#40;$my_mail&#91;'to'&#93;&#91;'name'&#93; == ""&#41; &#123; 
        $my_mail&#91;'to'&#93;&#91;'name'&#93; = $my_mail&#91;'to'&#93;&#91;'email'&#93;; 
    &#125;      
    $my_mail&#91;'to'&#93;&#91;'name'&#93; = ereg_replace&#40;"'","",$my_mail&#91;'to'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'to'&#93;&#91;'name'&#93; = ereg_replace&#40;""","",$my_mail&#91;'to'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'to'&#93;&#91;'name'&#93; = addslashes&#40;$my_mail&#91;'to'&#93;&#91;'name'&#93;&#41;; 
     
    // reply to 
    if &#40;$my_mail&#91;'replyto'&#93;&#91;'name'&#93; == ""&#41; &#123; 
        $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = $my_mail&#91;'from'&#93;&#91;'name'&#93;; 
    &#125; 
    if &#40;$my_mail&#91;'replyto'&#93;&#91;'email'&#93; == ""&#41; &#123; 
        $my_mail&#91;'replyto'&#93;&#91;'email'&#93; = $my_mail&#91;'from'&#93;&#91;'email'&#93;; 
    &#125; 
     
    $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = ereg_replace&#40;"'","",$my_mail&#91;'replyto'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = ereg_replace&#40;""","",$my_mail&#91;'replyto'&#93;&#91;'name'&#93;&#41;; 
    $my_mail&#91;'replyto'&#93;&#91;'name'&#93; = addslashes&#40;$my_mail&#91;'replyto'&#93;&#91;'name'&#93;&#41;; 
     
    $my_mail&#91;'cc'&#93; = ereg_replace&#40;"'","",$my_mail&#91;'cc'&#93;&#41;; 
    $my_mail&#91;'cc'&#93; = ereg_replace&#40;""","",$my_mail&#91;'cc'&#93;&#41;; 
    $my_mail&#91;'cc'&#93; = addslashes&#40;$my_mail&#91;'cc'&#93;&#41;; 
     
    $my_mail&#91;'bcc'&#93; = ereg_replace&#40;"'","",$my_mail&#91;'bcc'&#93;&#41;; 
    $my_mail&#91;'bcc'&#93; = ereg_replace&#40;""","",$my_mail&#91;'bcc'&#93;&#41;; 
    $my_mail&#91;'bcc'&#93; = addslashes&#40;$my_mail&#91;'bcc'&#93;&#41;; 
     
    $my_mail&#91;'subject'&#93; = addslashes&#40;$my_mail&#91;'subject'&#93;&#41;; 
     
    $my_mail&#91;'body'&#93; = strip_tags&#40;$my_mail&#91;'body'&#93;&#41;; 
    $my_mail&#91;'body'&#93; = addslashes&#40;$my_mail&#91;'body'&#93;&#41;; 

     
    // ---------------------------------------------------------------------------- // 
    // ---------------------------------------------------------------------------- // 
    // OUTPUT DEBUG 
    //print mailinfo &#40;debug only&#41; 
    debug&#40;"<br>",0&#41;; 
    debug&#40;"Type&#58; ".$my_mail&#91;'type'&#93;.""&#41;; 
    debug&#40;"Encoding&#58; ".$my_mail&#91;'tcode'&#93;.""&#41;; 
    debug&#40;"HEADER Date&#58; ".$my_mail&#91;'date'&#93;.""&#41;; 
    debug&#40;"HEADER From&#58; ".$my_mail&#91;'from'&#93;&#91;'name'&#93;." &#91;".$my_mail&#91;'from'&#93;&#91;'email'&#93;."&#93;"&#41;; 
    debug&#40;"HEADER To&#58; ".$my_mail&#91;'to'&#93;&#91;'name'&#93;." &#91;".$my_mail&#91;'to'&#93;&#91;'email'&#93;."&#93;"&#41;; 
    debug&#40;"HEADER ReplyTo&#58; ".$my_mail&#91;'replyto'&#93;&#91;'name'&#93;." &#91;".$my_mail&#91;'replyto'&#93;&#91;'email'&#93;."&#93;"&#41;; 
    debug&#40;"HEADER CC&#58; ".$my_mail&#91;'cc'&#93;.""&#41;; 
    debug&#40;"HEADER BCC&#58; ".$my_mail&#91;'bcc'&#93;.""&#41;; 
    debug&#40;""&#41;; 
    debug&#40;"HEADER Subject&#58; ".$my_mail&#91;'subject'&#93;.""&#41;; 
     
    // ---------------------------------------------------------------------------- // 
    // ---------------------------------------------------------------------------- // 
    // Some output and action based on triggers 
    if &#40;$my_config&#91;'display_content'&#93;&#41; &#123; 
        debug&#40;"<hr size="1" noshade>>>>>>>>>> BODY <<<<<<<<<br><pre>".$my_mail&#91;'body'&#93;."</pre> <br><hr size="1" noshade>"&#41;; 
    &#125; 
     
    // send email 
    if &#40;$my_config&#91;'sendmail'&#93;&#41; &#123; 
        if &#40;$sendmailr = mail&#40;$my_config&#91;'sendmail'&#93;,$my_master&#91;'loopindex'&#93;,$my_mail&#91;'body'&#93;&#41;&#41; &#123; 
            debug&#40;"Mail sent successfully"&#41;; 
        &#125; else &#123; 
            debug&#40;"Send mail failed"&#41;; 
        &#125; 
    &#125; else &#123; 
        debug&#40;"Send mail turned OFF"&#41;; 
    &#125; 
     
    // move mail to an other IMAP folder 
    if &#40;$my_config&#91;'move_mail'&#93; != ""&#41; &#123; 
        if &#40;$move_mailr = imap_mail_move&#40;$imapmailbox,$my_master&#91;'loopindex'&#93;,$my_config&#91;'move_mail'&#93;&#41;&#41; &#123; 
            debug&#40;"Mail successfully moved to ".$imaphost.$my_config&#91;'move_mail'&#93;.""&#41;; 
        &#125; else &#123; 
            debug&#40;"Mail could not be moved to ".$imaphost.$my_config&#91;'move_mail'&#93;.""&#41;; 
        &#125; 
    &#125; else &#123; 
        debug&#40;"Move Mail turned OFF"&#41;; 
    &#125; 
         
    // Mark mail for deletion, exept if moved 
    if &#40;$my_config&#91;'delete_mail'&#93; && $my_config&#91;'move_mail'&#93; == ""&#41; &#123; 
        if &#40;$delete_mailr = imap_delete&#40;$imapmailbox,$my_master&#91;'loopindex'&#93;&#41;&#41; &#123; 
            debug&#40;"Mail successfully marked for deletion"&#41;; 
            $mailsdeleted++; 
        &#125; else &#123; 
            debug&#40;"Mail could not be marked for deletion"&#41;; 
        &#125; 
    &#125; else &#123; 
        debug &#40;"Mark Mail for deletion OFF"&#41;; 
    &#125; 


    // ---------------------------------------------------------------------------- // 
    // Insert mail to Database 


    if &#40;!isset&#40;$dirname&#41;&#41; &#123; 
        $dirname = 0; 
    &#125; 
     
    // INSERT MAIL TO SQL 
    $my_mail&#91;'body'&#93; = mysql_real_escape_string&#40;$my_mail&#91;'body'&#93;,$dbh&#41;; 
	$sql = "INSERT INTO `email` &#40; 
				`id` , 
				`date` , 
				`type` , 
				`encoding` , 
				`folder` , 
				`from_name` , 
				`from_mail` , 
				`to_name` , 
				`to_mail` , 
				`subj` , 
				`text` , 
				`cc` , 
				`dir` &#41; VALUES &#40;
							'', 
							'".$my_mail&#91;'date'&#93;."', 
							'".$my_mail&#91;'type'&#93;."', 
							'".$my_mail&#91;'tcode'&#93;."', 
							'".$my_config&#91;'folder'&#93;."', 
							'".$my_mail&#91;'from'&#93;&#91;'name'&#93;."', 
							'".$my_mail&#91;'from'&#93;&#91;'email'&#93;."', 
							'".$my_mail&#91;'to'&#93;&#91;'name'&#93;."', 
							'".$my_mail&#91;'to'&#93;&#91;'email'&#93;."', 
							'".$my_mail&#91;'subject'&#93;."', 
							'".$my_mail&#91;'body'&#93;."', 
							'".$my_mail&#91;'cc'&#93;."', 
							'".$dirname."'&#41;;";
    //$sql = "INSERT INTO `email` &#40; `id` , `date` , `type` , `encoding` , `folder` , `answer` , `from_name` , `from_mail` , `to_name` , `to_mail` , `replyto_name` , `replyto_mail` , `subj` , `text` , `cc` , `dir`, &#41; VALUES &#40;'' , '".$my_mail&#91;'date'&#93;."' , '".$my_mail&#91;'type'&#93;."' , '".$my_mail&#91;'tcode'&#93;."' , '".$my_config&#91;'folder'&#93;."' , '".$my_mail&#91;'from'&#93;&#91;'name'&#93;."' , '".$my_mail&#91;'from'&#93;&#91;'email'&#93;."' , '".$my_mail&#91;'to'&#93;&#91;'name'&#93;."' , '".$my_mail&#91;'to'&#93;&#91;'email'&#93;."' , '".$my_mail&#91;'replyto'&#93;&#91;'name'&#93;."' , '".$my_mail&#91;'replyto'&#93;&#91;'email'&#93;."' , '".$my_mail&#91;'subject'&#93;."' , '".$my_mail&#91;'body'&#93;."' , '".$my_mail&#91;'cc'&#93;."' , '$dirname'&#41;"; 
    if &#40;$my_config&#91;'writetoDB'&#93;&#41; &#123; 
        if &#40;$result = mysql_query&#40;$sql,$dbh&#41; or die&#40;mysql_error&#40;&#41; . '<BR><i>' . $sql . '</i>'&#41;&#41; &#123; 
            debug&#40;"Saved Mail to Database"&#41;; 
        &#125; else &#123; 
            debug&#40;"Save Mail to Database failed! ---> ",0&#41;; 
            //debug&#40;mysql_error&#40;&#41;&#41;; 
        &#125; 
    &#125; else &#123; 
        debug&#40;"Save mail to database OFF"&#41;; 
    &#125; 
     
     
    debug&#40;"<br><br>---------------------eof-------------------------<br><br><hr size="3" noshade><br>"&#41;; 
    $my_master&#91;'loopindex'&#93;++; 

    // ---------------------------------------------------------------------------- // 
    // Unset some variables before looping to next mail 
    unset&#40;$attachs_error_echo, $dirname, $dirpath, $my_mail&#41;; 

&#125; 
// END LOOP => NEXT MAIL 
// ---------------------------------------------------------------------------- // 
// ---------------------------------------------------------------------------- // 
// ---------------------------------------------------------------------------- // 




// ---------------------------------------------------------------------------- // 
// Display final debug information and close IMAP/mySQL 
debug&#40;"<br><br><hr size="3" noshade>"&#41;; 

// delete mails marked for deletion 
if &#40;$expunge_mails = imap_expunge&#40;$imapmailbox&#41;&#41; &#123; 
    debug&#40;"Mails marked for deletion successfully deleted from server -> ".$mailsdeleted." Mails"&#41;; 
&#125; else &#123; 
    debug&#40;"Mails marked for deletion &#40;".$mailsdeleted."&#41; could not be deleted from server"&#41;; 
&#125; 
     
// close IMAP 
if &#40;$imap_close = imap_close&#40;$imapmailbox&#41;&#41; &#123; 
    debug&#40;"Closed connection to IMAP Server successfully"&#41;; 
&#125; else &#123; 
    debug&#40;"Closing IMAP connection failed!"&#41;; 
&#125; 

// close mySQL 
if &#40;$mysql_close = mysql_close&#40;$dbh&#41;&#41; &#123; 
    debug &#40;"Closed connection to mySQL Server successfully"&#41;; 
&#125; else &#123; 
    debug&#40;"Closing mySQL connection failed!"&#41;; 
&#125; 

// ---------------------------------------------------------------------------- // 
// DEBUG Function 
function debug&#40;$output,$nobrake=TRUE&#41; &#123; 
    global $my_config; 
     
    if &#40;$my_config&#91;'debug'&#93;&#41; &#123; 
        echo $output; 
        if &#40;$nobrake&#41; &#123; 
            echo "<br>"; 
        &#125; 
        return TRUE; 
    &#125; 
&#125; 


// RANDOM FOLDER NAME 
function random&#40;$length=16&#41; &#123; 
    $seeds = 'abcdefghijklmnopqrstuvwxyz123456789'; 
    $seeds_count = strlen&#40;$seeds&#41;; 
    // Seed 
    list&#40;$usec, $sec&#41; = explode&#40;' ', microtime&#40;&#41;&#41;; 
    $seed = &#40;float&#41; $sec + &#40;&#40;float&#41; $usec * 100000&#41;; 
    mt_srand&#40;$seed&#41;; 
    // Generate 
    for &#40;$i = 0; $length > $i; $i++&#41; &#123; 
        $str .= $seeds&#123;mt_rand&#40;0, $seeds_count - 1&#41;&#125;; 
    &#125; 
    return $str; 
&#125;             

// ---------------------------------------------------------------------------- // 
$time = microtime&#40;&#41;; 
$time = explode&#40;' ', $time&#41;; 
$time = $time&#91;1&#93; + $time&#91;0&#93;; 
$finish = $time; 
$total_time = round&#40;&#40;$finish - $start&#41;, 6&#41;; 
debug &#40;"Execution time&#58; $total_time s"&#41;; 
?> 
    </span></td> 
  </tr> 
</table> 
</body>
</html>