Edilson, o código abaixo informa o nome do arquivo que veio anexo no email ...<br><br><br>&lt;codigo&gt;<br>#!/usr/bin/perl<br>use strict;<br>use MIME::Parser;<br><br>#Dê uma olhada no schema no link <a href="http://search.cpan.org/~doneill/MIME-tools-5.426/lib/MIME/Tools.pm">http://search.cpan.org/~doneill/MIME-tools-5.426/lib/MIME/Tools.pm</a><br>
<br>my $parse&nbsp; = MIME::Parser-&gt;new;<br>my $entity = $parse-&gt;parse(\*STDIN) or die &quot;parse failed\n&quot;; <br><br>foreach ( $entity-&gt;parts() ) {<br>&nbsp; print $_-&gt;head-&gt;mime_type,&quot;\n&quot;;<br>&nbsp; print $_-&gt;head-&gt;recommended_filename,&quot;\n&quot;;<br>
&nbsp; print &quot;*&quot; x 50;<br>&nbsp; print &quot;\n&quot;;<br>}<br>&lt;/codigo&gt;<br><br><div class="gmail_quote">2008/6/10 Edilson Azevedo &lt;<a href="mailto:eazevedo@bsd.com.br">eazevedo@bsd.com.br</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Caramba!<br>
<br>
Quantas respostas em tão pouco tempo! Fiquei impressionado!<br>
<br>
Segue abaixo os dados solicitados:<br>
<br>
Código:<br>
<br>
############################################################<br>
#!/usr/bin/perl<br>
<br>
use MIME::Parser;<br>
use File::Basename;<br>
<br>
undef $/; # We want to treat everything read from STDIN as one line<br>
$input = &lt;&gt;;<br>
$/ = &quot;\n&quot;;<br>
($headers, $body) = split (/\n\n/, $input, 2);<br>
<br>
# Split MIME-multipart messages and store the parts in subdirectories<br>
# under the directory indicated by $output_path. Depending on which<br>
# mail system your site uses, the directory specified by $output_path might<br>
# have to have special permissions. If you have qmail, the dir should<br>
# be owned by the user &#39;alias&#39;. Sendmail should be content with &#39;root&#39;<br>
# as owner.<br>
my $output_path = &#39;/home/r232991/perl&#39;;<br>
my ($parsed) = (basename($0))[0];<br>
my $parser = MIME::Parser-&gt;new();<br>
<br>
# Permission mask for output files.<br>
# These permissions are very lax. Replace with what is appropriate<br>
# for your system.<br>
$oldumask = umask 0002;<br>
<br>
#$parser-&gt;output_under($output_path);<br>
$parser-&gt;output_prefix($parsed);<br>
$parser-&gt;output_to_core();<br>
<br>
my $entity = $parser-&gt;parse_data($input);<br>
# Permissions for the directory containing the output files.<br>
# These permissions are very lax. Replace with what is appropriate<br>
# for your system.<br>
chmod 0775, ($parser-&gt;output_dir);<br>
<br>
# Process the headers:<br>
$procheaders = $headers;<br>
$procheaders =~ s/\?=\s\n/\?=\n/g; # Lines ending with an encoded-word<br>
# have an extra space at the end. Remove it.<br>
$procheaders =~ s/\n[ |\t]//g; # Merge multi-line headers into a single<br>
line.<br>
$transheaders = &#39;&#39;;<br>
<br>
foreach $line (split(/\n/, $procheaders))<br>
{<br>
while ($line =~ m/=\?[^?]+\?(.)\?([^?]*)\?=/)<br>
{<br>
$encoding = $1;<br>
$txt = $2;<br>
$str_before = $`;<br>
$str_after = $&#39;;<br>
<br>
# Base64<br>
if ($encoding =~ /b/i)<br>
{<br>
require MIME::Base64;<br>
MIME::Base64-&gt;import(decode_base64);<br>
$txt = decode_base64($txt);<br>
}<br>
<br>
# QP<br>
elsif ($encoding =~ /q/i)<br>
{<br>
require MIME::QuotedPrint;<br>
MIME::QuotedPrint-&gt;import(decode_qp);<br>
$txt = decode_qp($txt);<br>
}<br>
<br>
$line = $str_before . $txt . $str_after;<br>
}<br>
# The decode above does not do underline-to-space translation:<br>
$line =~ tr/_/ /;<br>
$transheaders .= $line . &quot;\n&quot;;<br>
}<br>
<br>
# Reconstruct the message, made from headers and the MIME text parts<br>
# we saved earlier. Add references in the message body to the non-text<br>
# parts that have been stripped out and stored. The purgeable method<br>
# returns the full path of the files constructed from the different<br>
# message parts.<br>
print $transheaders . &quot;\n&quot;;<br>
<br>
foreach $file ($parser-&gt;filer-&gt;purgeable) {<br>
# Strip trailing spaces from filenames:<br>
$file =~ /(\S*)\s*$/;<br>
$file = $1;<br>
if ($file =~ /\.txt\s*$/) {<br>
# We have found a plaintext part. Include it in the new body:<br>
#open PART, $file;<br>
#while (&lt;PART&gt;) {<br>
# print;<br>
#}<br>
#close PART;<br>
# Build list of files included in the new body. We will delete<br>
# these files further down.<br>
unshift @purgeables, $file;<br>
}<br>
else {<br>
# We have found a non-plaintext part. Add a reference to it in the<br>
# new body:<br>
print &quot;\n\n** Attachment decoded and saved to \n** $file\n\n&quot;;<br>
}<br>
}<br>
<br>
# Make the list we built the new list of purgeable files:<br>
$parser-&gt;filer-&gt;purgeable(\@purgeables);<br>
# Delete them:<br>
$parser-&gt;filer-&gt;purge;<br>
<br>
umask $oldumask;<br>
###############################################<br>
<br>
Saída do comando em cima de uma mensagem:<br>
<br>
##############################################################<br>
<br>
Return-Path: &lt;jcarlos <a href="mailto:barbosa@blabla.com.uk">barbosa@blabla.com.uk</a>&gt;<br>
Delivered-To: <a href="mailto:faoliveira@blabla.com.uk">faoliveira@blabla.com.uk</a><br>
Received: from <a href="http://10.21.179.136" target="_blank">10.21.179.136</a><br>
Message-ID:<br>
&lt;<a href="mailto:1269.10.21.179.136.1212062961.squirrel@metromail.clusclus.uk.gov.uk">1269.10.21.179.136.1212062961.squirrel@metromail.clusclus.uk.gov.uk</a>&gt;<br>
Date: Thu, 29 May 2008 09:09:21 -0300 (ukT)<br>
Subject: [Fwd: Fw: FW: En: [Fwd: simplesmente impressionante!!!!!!!]]]]]<br>
From: &quot;Jose Carlos Barbosa&quot; &lt;jcarlos <a href="mailto:barbosa@blabla.com.uk">barbosa@blabla.com.uk</a>&gt;<br>
To: euripedes <a href="mailto:ferreira@blabla.com.uk">ferreira@blabla.com.uk</a><br>
MIME-Version: 1.0<br>
Content-Type: multipart/mixed;boundary=&quot;----= 20080529090921 24520&quot;<br>
X-Priority: 3 (Normal)<br>
Importance: Normal<br>
<br>
--------------------------- Mensagem Original ----------------------------<br>
Assunto: [Fwd: Fw: FW: En: [Fwd: B?BLIA- simplesmente<br>
impressionante!!!!!!!]]]]]<br>
De: &quot;Francisco Assis Oliveira&quot; &lt;<a href="mailto:faoliveira@blabla.com.uk">faoliveira@blabla.com.uk</a>&gt;<br>
Data: Qua, Maio 28, 2008 2:47 pm<br>
Para:<br>
--------------------------------------------------------------------------<br>
<br>
** Attachment decoded and saved to<br>
** ./untitled-1.2<br>
<br>
<br>
<br>
** Attachment decoded and saved to<br>
** ./untitled-1-1.2<br>
<br>
<br>
<br>
** Attachment decoded and saved to<br>
** ./Biblia.pps<br>
<br>
##########################################################<br>
<br>
<br>
Dados históricos comprovam que em 06/10/2008 12:52 PM, Edilson Azevedo<br>
aparentemente escreveu a mensagem abaixo::<br>
<div class="Ih2E3d">&gt; Olá pessoal!<br>
&gt;<br>
&gt; Sou novo por aqui e essa é a minha primeira pergunta... espero um dia<br>
&gt; estar respondendo algumas também hehe.<br>
&gt;<br>
&gt; Seguinte, possuo um script em perl que analiza uma mensagem de email e<br>
&gt; separa apenas o header dela. Até aí tudo perfeito, porém esse mesmo<br>
&gt; script separa o anexo da mensagem - se tiver - e salva na pasta onde<br>
&gt; ele mesmo está rodando.<br>
&gt;<br>
&gt; O que eu preciso - creio eu - é bem simples: Quero que ao invés que<br>
&gt; ele salve o anexo em disco, quero que ele apenas me mostre o nome do<br>
&gt; anexo, sem salva-lo em disco, sacaram?<br>
&gt;<br>
&gt; Nos links abaixo eu tenho uma amostra da saída do script após realizar<br>
&gt; a filtragem do email e o link para vcs visualizarem o script.<br>
&gt;<br>
&gt;<br>
&gt; Exemplo de saída do script:<br>
&gt; <a href="http://sites.google.com/site/apropos/Home/saidadoemail.txt?attredirects=0" target="_blank">http://sites.google.com/site/apropos/Home/saidadoemail.txt?attredirects=0</a><br>
&gt;<br>
&gt; LINK para baixar o script:<br>
&gt; <a href="http://sites.google.com/site/apropos/Home/mail.pl?attredirects=0" target="_blank">http://sites.google.com/site/apropos/Home/mail.pl?attredirects=0</a><br>
&gt;<br>
&gt; Obrigado mesmo pessoal!!!<br>
&gt;<br>
<br>
</div><div><div></div><div class="Wj3C7c">_______________________________________________<br>
SaoPaulo-pm mailing list<br>
<a href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>&quot;o animal satisfeito dorme&quot;. - Guimarães Rosa