Como ler uma mensagem de email - no formato original

2 respostas
Rafael_Nascimento

galera, tenho um conjunto de mensagens de email - no formato original, em arquivos .txt (como no exemplo abaixo) - salvos em uma máquina, possivelmente offline

queria saber se é possível, usando a API javaMail (ou outra se houver), de ler cada mensagem e poder resgatar facilmente informações como: destinatários, emissor, conteúdo, anexo (se houver)

já escrevi código para enviar email, e nesse caso eu definia destinatários, emissor, conteúdo, anexos… (e pelo console via q o java gerava um arquivo com códigos semelhante ao abaixo) ,

mas agora parece q preciso fazer o processo inverso, ou seja, tenho os arquivos originais de cada mensagem e preciso resgatar partes específicas

obrigado!!

segue o exemplo do código q tenho nos txt

Delivered-To: [email removido]
Received: by 10.58.64.133 with SMTP id o5csp232591ves;
        Thu, 4 Oct 2012 06:05:35 -0700 (PDT)
Received: by 10.50.104.137 with SMTP id ge9mr5133053igb.17.1349355934745;
        Thu, 04 Oct 2012 06:05:34 -0700 (PDT)
Return-Path: <[email removido]>
Received: from response.sourceforge.com (response.sourceforge.com. [74.116.233.70])
        by mx.google.com with ESMTP id rl8si13978256pbc.52.2012.10.04.06.05.34;
        Thu, 04 Oct 2012 06:05:34 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email removido] designates 74.116.233.70 as permitted sender) client-ip=74.116.233.70;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of [email removido] designates 74.116.233.70 as permitted sender) smtp.mail=[email removido]; dkim=pass header.i=@goparallel.sourceforge.com
Received: from mail6.elabs10.com (10.10.10.56) by response.sourceforge.com (PowerMTA(TM) v3.5r15) id hdm4ps0vd5cg for <[email removido]>; Thu, 4 Oct 2012 06:05:15 -0700 (envelope-from <[email removido]>)
To: <[email removido]>
Subject: =?utf-8?Q?Boost=20Your=20Code=20Performance=20with=20Vectorization?=
Date: Thu, 04 Oct 2012 06:05:15 -0700
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=goparallel.sourceforge.com; s=s2010001400a; h=Reply-To:From; bh=hvsr+GXDdWtmne1dMQzRMjS6Qcg=; b=BxfpeNrmhI0tp5VfnSShCY1v/ooC87g0wvOV4+UXfSEcjPj4azuvNm7dA+44x26auQ6yPPPSFIlmNwprIPdv+w==
X-EmailAdvisor: 2016371
X-Delivery: Custom [telefone removido]
Reply-To: [email removido]
List-Unsubscribe: <mailto:[email removido]?subject=[email removido]>
Content-description: [email removido]!33023!1ec473!77ce2ff8!rynof10.pbz!
X-Complaints-To: [email removido]
Message-Id: <[email removido]>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="=_69308e38a03476f1fd2e383a0358e937"
From: "=?utf-8?Q?Go=20Parallel=20Update?=" <[email removido]>

This is a MIME encoded message.

--=_69308e38a03476f1fd2e383a0358e937
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

Don't miss a single issue of the Go Parallel Newsletter. Add [email removido] to your address book.

Go Parallel Newsletter - Translating Multicore Power into Application Performance


Editor's Pick 

Boost Your Code Performance with Vectorization
Vectorization, which is parallelism that can be achieved within a single CPU core, can provide a significant performance improvement for your code, according to Intel's Shannon Cepeda and Wendy Doerner. Watch their presentation to learn more about vectorization, including why it's important to forward scalability. Then email us at [email removido] to let us know what you think.
Watch Video>> http://goparallel.sourceforge.com/ct.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,8l8k,dyk7,dcfk,1abl



******************************************************************************************************************************************************************************************
You are subscribed to this Resource Newsletter as [email removido]
To unsubscribe, send an email to: [email removido]
SourceForge | 594 Howard Street,  Suite 300  |  San Francisco, CA  94105
To view our Privacy Policy click here : http://goparallel.sourceforge.com/ct.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,7jms,4lrq,dcfk,1abl

--=_69308e38a03476f1fd2e383a0358e937
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<html><head>     <title>Newsletter Left Column</title>   </head>   <body vlink="#0066cc" link="#0066cc" bgcolor="#ebf1fc" alink="#0066cc"><table width="780" border="0" bgcolor="#ffffff" align="center" cols="2" cellspacing="5" cellpadding="20">       <tbody>         <tr>           <td
width="65%"><div><p class="MsoNoSpacing"><strong><span style="font-size: 10pt;"><span style="font-family: Arial;"><br /></span></span></strong><span style="font-family: Arial;"><span style="font-size: 10pt;"><span style="text-decoration: underline;">Don't miss a single issue of the Go Parallel
newsletter. Add [email removido] to your address book.</span></span></span></p>               <div class="asset"><a href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,i902,1we0,dcfk,1abl"><span style="font-family: Arial;"><img border="0"
title="2596_Intel_GoParallel_Newsletter_Header.png" alt="" src="http://www.elabs10.com/content/[telefone removido]/2596_Intel_GoParallel_Newsletter_Header.png" /></span></a></div>               <div class="asset"><span style="font-family: Arial;">&nbsp;</span></div>               <div class="asset"><div
class="asset"><a href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,i902,1we0,dcfk,1abl"><span style="font-family: Arial;"><img border="0" title="2596_Intel_GoParallel_EditorsPick.png" alt=""
src="http://www.elabs10.com/content/[telefone removido]/2596_Intel_GoParallel_EditorsPick.png" /></span></a></div><a href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,6idw,eulg,dcfk,1abl"><span style="font-family: Arial;"><br /></span></a>                                       
           <div class="asset"><p><span style="font-size: 12pt;"><span style="font-family: Arial;"><a href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,8l8k,dyk7,dcfk,1abl">Boost Your Code Performance with Vectorization </a><br />Vectorization, which is parallelism that
can be achieved within a single CPU core, can provide a significant performance improvement for your code, according to Intel's Shannon Cepeda and Wendy Doerner. Watch their presentation to learn more about vectorization, including why it's important to forward scalability. Then email us at <a
href="mailto:[email removido]">[email removido]</a> to let us know what you think.</span></span></p><div class="asset"><div class="asset"><div class="asset"><div class="asset"><a
href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,8l8k,dyk7,dcfk,1abl"><img border="0" alt="" src="http://www.elabs10.com/content/[telefone removido]/2596_Intel_GoParallel_Button_WatchVideo_v2.gif" title="2596_Intel_GoParallel_Button_WatchVideo_v2.gif"
/></a></div></div></div></div><p></p><p></p></div>                 <div class="asset"><div class="asset"><div class="asset"><span style="font-size: 12pt;"><span style="font-family: Arial;">&nbsp;</span></span><br /><div class="asset"><span style="font-size: 12pt;"><span style="font-family:
Arial;"><br /></span></span></div>                       <div class="asset"><span style="font-family: Arial;">&nbsp;</span></div>                       <div class="asset"><div style="text-align: center"><span style="font-family: Arial;"><span style="color: #808080;"><span style="font-size:
10pt;">You are subscribed to this Newsletter as [email removido] </span></span></span></div>                         <div style="text-align: center"><div style="text-align: center"><span style="font-family: Arial;">&nbsp;<span style="color: #808080;"><span style="font-size: 10pt;">To
unsubscribe, <a href="http://goparallel.sourceforge.com/functions/mailing_list.html?mid=2016371&submitaction=2&mlid=208931&activity=submit&siteid=[telefone removido]&email=[email removido]&redirection=http%3A%2F%2Fgoparallel.sourceforge.com%2Ffunctions%2Funsubscribed.html">click here</a> or send an email
to: [email removido]<br />                                                                                       SourceForge | 594 Howard Street, Suite 300 | San Francisco, CA 94105                                                                                       <br />            
                                                                          To view our Privacy Policy click </span></span></span><span style="font-size: 11pt"><span style="color: #333399"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="color: #808080"><font face="arial,
verdana, sans-serif"><a href="http://goparallel.sourceforge.com/c.html?ufl=9&rtr=on&s=x8pb08,177ub,4h7n,me80,eapd,dcfk,1abl"><span style="font-family: Arial;">here.</span></a></font><span style="font-family: Arial;">
</span></span></span></span></span></span></div></div></div></div></div></div></div></div></td>         </tr>       </tbody>     </table>     <div><span style="font-family: Arial;"><span style="font-size: 11pt;">&nbsp;</span></span></div>     <p><span style="font-family: Arial;"><span
style="font-size: 11pt;">&nbsp;</span></span></p><img src="http://goparallel.sourceforge.com/images/mlopen_post.html?rtr=on&siteid=[telefone removido]&mid=2016371&mlid=208931&uid=980300ea81"></body></html>

--=_69308e38a03476f1fd2e383a0358e937--

2 Respostas

O

Aparentemente, o email foi salvo em formato .eml (não conheço a especificação, mas o outlook leu o arquivo).
Dei uma googlada e achei este exemplo para ler os dados do arquivo .eml: http://www.rgagnon.com/javadetails/java-0458.html
Acho que já é um caminho para seguir…

Rafael_Nascimento

valeu , oyama

eu já tinha tentado essa alternativa
agora q eu vi, meu problema estava com a IDE, estou usando NetBeans 7.2 e eu fico obtendo esse erro maluco

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Session

testei agora pouco e o mesmo código, com o mesmo classpath, apontando para o mesmo diretório jdk, no Eclipse e funcionou, consegui ler o arquivo !!

Criado 10 de outubro de 2012
Ultima resposta 10 de out. de 2012
Respostas 2
Participantes 2