Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

    /**
     * @package   Kein Projekt geladen
     * @author     <>
     * @copyright 2009 
     * @license   propietary http://www.weban.de
     * @version   $Rev: 3361 $
     * @filesource
     * 
     */

    /**
     * 
     * @package   Kein Projekt geladen
     * @author     <>
     * @copyright 2009 
     */

    // SVN: $Id: mail.php 3361 2011-02-24 15:34:41Z tiefland $

    setlocale( LC_TIME, "de_DE" );
    date_default_timezone_set( "Europe/Berlin" );
    function getMessageIds()
    {
        $ret = array();
        $sql = "
            SELECT
                m_id
            FROM
                dokumente
            WHERE
                m_id IS NOT NULL
        ";
        $res = mysql_query( $sql );
        while ( $row = mysql_fetch_assoc($res) )
        {
            $ret[] = $row["m_id"];
        }
        return $ret;
    }

    require_once  "../../Online-Shop/connect2.php";

    require_once  "/web/apache/content-management/Warenwirtschaft/MailClient/mail_func.php";

    $m_ids = getMessageIds();

    $mbox = imap_open( "{mail.mediaran.de:143/imap/novalidate-cert}",
        "rs@mediaran.de", "EW-ad-1055" );

    $headers = imap_headers( $mbox );

    $m_delted = 0;

    if ( $headers == false )
    {
        echo "Abruf fehlgeschlagen<br />\n";
    }
    else
    {
        foreach ( $headers as $n => $val )
        {
            $html = false;
            $head = imap_header( $mbox, $n + 1 );
            $date = strftime( "%x", strtotime($head->Date) );
            $time = strftime( "%X", strtotime($head->Date) );
            $m_id = $head->message_id;
            $subject = imap_mime_header_decode( $head->subject );
            $Bestellung = false;
            if ( preg_match("/[0-9]{6}/", $head->subject, $id) && !in_array
                ($m_id, $m_ids) )
            {
                $id = $id[0];
                $struct = imap_fetchstructure( $mbox, $n + 1 );
                if ( $struct->subtype == "PLAIN" )
                {
                    $body = imap_qprint( imap_body($mbox, $n + 1) );
                } elseif ( $struct->subtype == "ALTERNATIVE" )
                {
                    $body = nl2br( imap_qprint(imap_fetchbody($mbox, $n + 1,
                        1)) );
                    $html = true;
                } elseif ( $struct->subtype == "MIXED" )
                {
                    $body = imap_qprint( imap_fetchbody($mbox, $n + 1, "1.2") );
                    $html = true;
                }
                if ( is_string($body) )
                {
                    $ln_id = generate_LN( $id, "K" );
                    if ( $html )
                    {
                        $body = $head->fromaddress . " schrieb am " . $date .
                            " um $time Uhr:<br>$body";
                        $d_id = create_html_pdf( $id, '', '', $body, 'K', $ln_id );
                    }
                    else
                    {
                        $body = $head->fromaddress . " schrieb am " . $date .
                            " um $time Uhr:\n$body";
                        $d_id = create_pdf( $id, '', '', $body, 'K', $ln_id );
                    }
                    $sql = "
                        UPDATE
                            dokumente
                        SET
                            m_id='$m_id'
                        WHERE
                            id=$d_id
                    ";
                    $res = mysql_query( $sql );
                }
            }
        }
    }
    imap_close( $mbox );
?>