Email Anhänge Automatisch speichern

Gibt es eine Möglichkeint in IPS bzw. PHP Email Anhänge zu auf der HDD zu Speichern.

Evtl. solltest du deine Fragestellung nochmal überarbeiten.
Zumindest ich kann damit viele Optionen in Betracht ziehen…

Anhänge zu auf der HDD zu Speichern
:confused: :eek:

wie? -das war ne Frage?
:D:D

… wenn ich das gewusst hätte… Die Antwort wäre wohl „ja“ gewesen :smiley:

Ok dann mich ich das ganze nochmal!! schäm Ich möchte mir eine Email schicken von der Maloche aus oder wo immer ich bin, mit einem Anhang.

Dann will ich mit IPS diese Email empfangen . < — Kein Problem
Jetzt möchte ich aber wenn ein Anhang vorhaden ist , den Automatisch aus der Email raus auf der Lokalen Festplatte im Ordner C:/IP_Symcon/media/anhänge/ speichern.

Beispielsweise eine Text Datein um irgendwas damit zu Steuern.

Ich hoffe das ein wenig verständlicher !!

Danke schön , werde ich gleich heute Abend ausprobieren

Es klappt soweit

allerdings klappt es nur wenn die Anhänge jpg sind. Bei einer .txt oder .csv
klappt es noch nicht .
Aber da komme ich als Copy und Paste Programmier auch noch hinter :D.
Hier mal der Quellcode


// opens connection to a mailbox
 $username = 'user';
 $password = 'passwd';
 
$mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", $username, $password);
//$mbox = $mailbox = imap_open("imap.goooglemail.comINBOX", $username, $password);

function parsepart($p,$i)
{
global $mbox,$msgid,$partsarray,$j;
//where to write file attachments to:
$filestore = "D:/anhaenge/";
//echo "link ".$mbox." msgnum ".$msgid. "p ".$p." i ".$i." ARR ".$partsarray."<br>";

//fetch only a part of the body
$part=imap_fetchbody($mbox,$msgid,$i);

//if type is not text
if ($p->type!=0)
{
//DECODE PART
//decode if base64
if ($p->encoding==3)
{$part=base64_decode($part);}
//decode if quoted printable
if ($p->encoding==4)
{$part=quoted_printable_decode($part);}
//no need to decode binary or 8bit!

//get filename of attachment if present
$filename='';


// if there are any dparameters present in this part
if (count($p->dparameters)>0)
{
foreach ($p->dparameters as $dparam)
{
if ((strtoupper($dparam->attribute)=='NAME')
||(strtoupper($dparam->attribute)=='FILENAME'))
{
$filename=$dparam->value;
}
}
}


//if no filename found
if ($filename=='')
{
// if there are any parameters present in this part
if (count($p->parameters)>0)
{
foreach ($p->parameters as $param)
{
if ((strtoupper($param->attribute)=='NAME')
||(strtoupper($param->attribute)=='FILENAME'))
{
$filename=$param->value;
}
}
}
}


//write to disk and set partsarray variable
if ($filename!='')
{
$partsarray[$i][attachment] = array('filename'=>$filename,'binary'=>$part);
$filename = explode(".", $filename);
$fp=fopen($filestore.$filename[0].$j.".".$filename[1],"w+");
fwrite($fp,$part);
fclose($fp);
}


}//end if type!=0

//if part is text
else if($p->type==0)
{
//decode text
//if QUOTED-PRINTABLE
if ($p->encoding==4)
{$part=quoted_printable_decode($part);}
//if base 64
if ($p->encoding==3)
{$part=base64_decode($part);}

//if plain text
if (strtoupper($p->subtype)=='PLAIN')1;
//if HTML
else if (strtoupper($p->subtype)=='HTML')1;
$partsarray[$i][text] = array('type'=>$p->subtype,'string'=>$part);
}

// if subparts... recurse into function and parse them too!
// this is a recursive call of the function
if (count($p->parts)>0){
foreach ($p->parts as $pno=>$parr){
parsepart($parr,($i.'.'.($pno+1)));
}
}
return;
}

/*=============================================*/
/*============= End of Function ===============*/
/*=============================================*/

$number_of_emails = imap_num_msg($mbox);
print_r ($number_of_emails);

if($number_of_emails>0)
{
// Number of message which will be analysed
for ($j=1;$j<=$number_of_emails;$j++)
{
$msgid = $j;

//fetch structure of message
$s=imap_fetchstructure($mbox,$msgid);


/*================================================================*/

//checks if there are any parts

if (count($s->parts)>0)


	{
	foreach ($s->parts as $partno=>$partarr)
	{
//parse parts of email
parsepart($partarr,$partno+1);
}
}
//for not multipart messages
else{
//gets the full/whole body of the message
$text=imap_body($mbox,$msgid);
//decode if quoted-printable
if ($s->encoding==4) $text=quoted_printable_decode($text);
//OPTIONAL PROCESSING
if (strtoupper($s->subtype)=='PLAIN') $text=$text;
if (strtoupper($s->subtype)=='HTML') $text=$text;

$partsarray['not multipart'][text]=array('type'=>$s->subtype,'string'=>$text);
}

/*================================================================*/

// shows all parts
print_r($partsarray);
}
}

// close connection
imap_close ($mbox);

?>