You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by nitinjaiin <ni...@xchanging.com> on 2012/07/06 13:22:24 UTC

Removing attachments from .MSG file

Hi,

The rquirement is to remove the attachments from the .MSG file and save the
.MSG file without the attachments. Is it possible using POI? If yes can you
please share the code?

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by lucaro <sa...@gmail.com>.
Nitin I am posting the code snippet here

POIFSFileSystem newDoc = new POIFSFileSystem();
POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(new
File("fileName")));
				
for(Entry entry : poifs.getRoot()){
	
    if(! entry.getName().startsWith(AttachmentChunks.PREFIX)) {
	 EntryUtils.copyNodeRecursively(entry, newDoc.getRoot());
      }
}
		
		
File fToWrite = new File("C:/CR0040POC/detachedMail/"+msgFile);
OutputStream out = new FileOutputStream(fToWrite);
newDoc.writeFilesystem(out);
out.close();

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710407.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by nitinjaiin <ni...@xchanging.com>.
basically .EML email files saved through lotus notes.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710397.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 6 Jul 2012, nitinjaiin wrote:
> .EML mail message

What kind? Lots of applications and file formats use .eml as their 
extension.... What application? What format? What mimetype? etc

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by nitinjaiin <ni...@xchanging.com>.
.EML mail message

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710395.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 6 Jul 2012, nitinjaiin wrote:
> Can you also let me know if the same is also possible when the file format
> is .EML?

What do you mean by an eml? I can think of several different formats that 
have all been known to use that file extension...

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by nitinjaiin <ni...@xchanging.com>.
okay, thanks

Can you also let me know if the same is also possible when the file format
is .EML?

That mean when .EML have several attachments which need to be removed and
save the .EML file without any attachment?

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710391.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 6 Jul 2012, nitinjaiin wrote:
> I want to remove all the attachments in an email and save the email 
> without the attachments, is it possible?

Yes, but you'll have to write some code yourself. See my email for details 
of the building blocks you'll want to use

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by nitinjaiin <ni...@xchanging.com>.
Sorry, may be i am not able to explain my problem.
I want to remove all the attachments in an email and save the email without
the attachments, is it possible?

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710387.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 6 Jul 2012, nitinjaiin wrote:
> The attachments could be .MSGs or any other file like .doc, .xls etc.
>
> I am unable to save the original .MSG file without the attachments. Multiple
> warnings can be included if it is not possible without the warnings.

You'll want to do a filtered copy of the POIFS. Either iterate through the 
nodes and pick yourself which to copy and which not to, or just something 
like FilteringDirectoryNode
<http://poi.apache.org/apidocs/org/apache/poi/poifs/filesystem/FilteringDirectoryNode.html> 
when you do it. EntryUtils 
<http://poi.apache.org/apidocs/org/apache/poi/poifs/filesystem/EntryUtils.html> 
should help you with the copying

See http://poi.apache.org/poifs/how-to.html for more on POIFS. Use 
HSMFDump 
<http://poi.apache.org/apidocs/org/apache/poi/hsmf/dev/HSMFDump.html> to 
help you work out which bits to copy, and which bits to ignore

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by nitinjaiin <ni...@xchanging.com>.
The attachments could be .MSGs or any other file like .doc, .xls etc.

I am unable to save the original .MSG file without the attachments. Multiple
warnings can be included if it is not possible without the warnings.

Does POI also supports .EML format?

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Removing-attachments-from-MSG-file-tp5710382p5710384.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Removing attachments from .MSG file

Posted by Nick Burch <ni...@alfresco.com>.
On 06/07/12 12:22, nitinjaiin wrote:
> The rquirement is to remove the attachments from the .MSG file and save the
> .MSG file without the attachments. Is it possible using POI? If yes can you
> please share the code?

What kind of attachments - other msg files, or anything else? (The 
outlook file format stores other messages in a totally different way to 
all other attachments)

And how many warnings can you put up with in Outlook when the 
attachments have been removed?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org