IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

Extraction des éléments d'un fichier *.msg.


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Septembre 2009
    Messages : 51
    Points : 45
    Points
    45
    Par défaut Extraction des éléments d'un fichier *.msg.
    Bonjour,

    Je souhaite extraire les éléments (corps, objet, fichiers annexes, etc.) ce, par
    PHP.

    Mailparse n'est pas installé par mon hébergeur...

    Des idées ?


    Merci d'avance !

  2. #2
    Membre éprouvé Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Points : 915
    Points
    915
    Par défaut class parseMail
    une class trouvé sur le net :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    <?php
        // parse an incoming mail
        // Version 0.5, 2005/03/16
        // Copyright (c) Frank Rust, TU Braunschweig (f.rust@tu-bs.de)
        //
        // This code is free software; you can redistribute it and/or modify
        // it under the terms of the GNU General Public License as published by
        // the Free Software Foundation; either version 2 of the License, or
        // (at your option) any later version.
        // 
        // This code is distributed in the hope that it will be useful,
        // but WITHOUT ANY WARRANTY; without even the implied warranty of
        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        // GNU General Public License for more details.
        // 
        // Since this is a very short Program the GNU General Public License
        // is not included. Please find it on the website of the Open Software
        // Foundation at
        //     http://www.fsf.org/licensing/licenses/lgpl.txt
        // or write to the Free Software Foundation, Inc., 59 Temple Place, 
        // Suite 330, Boston, MA  02111-1307  USA
     
        class parseMail {
            var $from="";
            var $to="";
            var $subject="";
            var $received="";
            var $date="";
            var $message_id="";
            var $content_type="";
            var $part =array();
     
            // decode a mail header
            function parseMail($text="") {
                $start=0;
                $lastheader="";
                while (true) {
                    $end=strpos($text,"\n",$start);
                    $line=substr($text,$start,$end-$start);
                    $start=$end+1;
                    if ($line=="") break; // end of headers!
                    if (substr($line,0,1)=="\t") {
                        $$last.="\n".$line;
                    }
                    if (preg_match("/^(From:)\s*(.*)$/",$line,$matches)) {
                        $last="from";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Received:)\s*(.*)$/",$line,$matches)) {
                        $last="received";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(To:)\s*(.*)$/",$line,$matches)) {
                        $last="to";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Subject:)\s*(.*)$/",$line,$matches)) {
                        $last="subject";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Date:)\s*(.*)$/",$line,$matches)) {
                        $last="date";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Content-Type:)\s*(.*)$/",$line,$matches)) {
                        $last="content_type";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Message-Id:)\s*(.*)$/",$line,$matches)) {
                        $last="message_id";
                        $$last=$matches[2];
                    }
                }
                $this->from=$from;
                $this->received=$received;
                $this->to=$to;
                $this->subject=$subject;
                $this->date=$date;
                $this->content_type=$content_type;
                $this->message_id=$message_id;
     
                if (preg_match("/^multipart\/mixed;/",$content_type)) {
                    $b=strpos($content_type,"boundary=");
                    $boundary=substr($content_type,$b+strlen("boundary="));
                    $boundary=substr($boundary,1,strlen($boundary)-2);
                    $this->multipartSplit($boundary,substr($text,$start));
     
                } else {
                    $this->part[0]['Content-Type']=$content_type;
                    $this->part[0]['content']=substr($text,$start);
                }
            }
            // decode a multipart header 
            function multipartHeaders($partid,$mailbody) {
                $text=substr($mailbody,$this->part[$partid]['start'],
                             $this->part[$partid]['ende']-$this->part[$partid]['start']);
     
                $start=0;
                $lastheader="";
                while (true) {
                    $end=strpos($text,"\n",$start);
                    $line=substr($text,$start,$end-$start);
                    $start=$end+1;
                    if ($line=="") break; // end of headers!
                    if (substr($line,0,1)=="\t") {
                        $$last.="\n".$line;
                    }
                    if (preg_match("/^(Content-Type:)\s*(.*)$/",$line,$matches)) {
                        $last="c_t";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Content-Transfer-Encoding:)\s*(.*)$/",$line,$matches)) {
                        $last="c_t_e";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Content-Description:)\s*(.*)$/",$line,$matches)) {
                        $last="c_desc";
                        $$last=$matches[2];
                    }
                    if (preg_match("/^(Content-Disposition:)\s*(.*)$/",$line,$matches)) {
                        $last="c_disp";
                        $$last=$matches[2];
                    }
                }
                if ($c_t_e=="base64") {
                    $this->part[$partid]['content']=base64_decode(substr($text,$start));
                    $c_t_e="8bit";
                } else {
                    $this->part[$partid]['content']=substr($text,$start);    
                }
                $this->part[$partid]['Content-Type']=$c_t;
                $this->part[$partid]['Content-Transfer-Encoding']=$c_t_e;
                $this->part[$partid]['Content-Description']=$c_desc;
                $this->part[$partid]['Content-Disposition']=$c_disp;
                unset($this->part[$partid]['start']);
                unset($this->part[$partid]['ende']);
            }
            // we have a multipart message body
            // split the parts 
            function multipartSplit($boundary,$text) {
                $start=0;
                $b_len=strlen("--".$boundary);
                $partcount=0;
                while (true) { // should have an emergency exit...
                    $end=strpos($text,"--".$boundary,$start);
                    if (substr($text,$end+$b_len,1)=="\n") {
                        // '\n' => part boundary
                        $this->part[$partcount]['start']=$end+$b_len+1;
                        if ($partcount) { 
                            $this->part[$partcount-1]['ende']=$end-1;
                            $this->multipartHeaders($partcount-1,$text);
                        }
                        $start=$end+$b_len+1;
                        $partcount++;
                    } else {
                        // '--' => end boundary
                        $this->part[$partcount-1]['ende']=$end-1;                
                        $this->multipartHeaders($partcount-1,$text);
                        break;
                    }
                }    
            }
        } 
     
    ?>
    Développeur informatique contrarié...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Septembre 2009
    Messages : 51
    Points : 45
    Points
    45
    Par défaut ...pour les fichiers MSG (outlook)
    En fait, il s'agit de fichiers au format *.msg (outlook).

    -> La classe citée plus haut ne semble pas fonctionner dans ce cas.

    Je désespère !

    -> >Autres idées bienvenues.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 10
    Dernier message: 20/02/2008, 11h57
  2. [Tableaux] Extraction des éléments d'un tableau
    Par djabeur dans le forum Langage
    Réponses: 6
    Dernier message: 09/09/2007, 08h03
  3. [débutant]extraction des données d'un fichier xml simple
    Par ekram dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 14/03/2007, 12h24
  4. [XSL][débutant]trié l'ordre des éléments d'un fichier xml
    Par pistache42 dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 19/04/2006, 10h37
  5. Récupération des éléments d'un fichier xml en flux retour
    Par opeo dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 07/11/2005, 10h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo