copy Attachement from Email on server (files copied are not valid)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nic den

    copy Attachement from Email on server (files copied are not valid)

    Hi,
    I'm getting emails from an address trough a script and I want to copy the
    attached files on the server. I can get the files and copy them on the
    server (trough the function below) BUT the files are not valid (images
    cannot be displayed)

    how can I solve this?

    ------------------------------------------
    function get_attachments ($mbox,$msgno){

    $o = imap_fetchstruc ture($mbox, $msgno);
    $dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST

    if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {

    $parts = $o->parts;
    $i=1;
    $retour = array();
    foreach($parts as $part) {
    $fname = '';

    if (!isset($part->encoding) && $part->encoding == 3) {
    $str = imap_base64(tri m(@imap_fetchbo dy($mbox, $msgno,$i)));
    } else {
    $str = imap_fetchbody( $mbox, $msgno,$i);
    }
    if ($part->ifdparameter s == 1) {
    $dparams = $part->dparameters;
    foreach($dparam s as $dparam) {
    if ($dparam->attribute == "FILENAME") {
    $fname = $dparam->value;
    }
    }
    }
    if ($fname=="") {
    if ($part->ifparameters == 1) {
    $params = $part->parameters;
    foreach($params as $param) {
    if ($param->attribute == "NAME") {
    $fname = $param->value;
    }
    }
    }
    }
    if ($fname=="") {$fname = "part$i";}

    $fp = fopen($dir.$fna me,"wb");
    if (!$fp) { return FALSE; }
    fwrite($fp,$str );
    fclose($fp);
    $i++;
    }
    return $retour;
    } else {
    return "no attach";
    }
    }


  • Guest's Avatar

    #2
    Re: copy Attachement from Email on server (files copied are not valid)

    "nic den" <ndengler@yahoo .fr> wrote in message
    news:3f587c11$1 @news.swissonli ne.ch...[color=blue]
    > Hi,
    > I'm getting emails from an address trough a script and I want to copy the
    > attached files on the server. I can get the files and copy them on the
    > server (trough the function below) BUT the files are not valid (images
    > cannot be displayed)
    >
    > how can I solve this?[/color]
    <snip users untested code>

    Aren't e-mail attachments Base64 encoded?


    Comment

    Working...