How to extract the zipped xls file from the email attachment? - excel

I have a module which is supposed to extract the email attachment and place it at a specific location. The code creates the POP3 Client to fetch the mail and has been using EMAIL::MIME::Attachment::Stripper module to extract the attachment as below.
my $mail=$pop->HeadAndBody($i);
my $parsed = Email::MIME->new($mail);
my $stripper = Email::MIME::Attachment::Stripper->new($parsed);
my #attachments = $stripper->attachments;
foreach my $a(#attachments)
{
next if $a->{content_type} !~ /octet-stream/i;
my $f = new IO::File "C:/MAIL_PARSING_DATA/" . "<filename>.<file-extension>", "w" or die "Can not create file!";
print $f $a->{payload};
goto EXITPOINT;
}
The code is working fine for the standard files identified by the Perl module, like spreadsheet etc. But not for the specific mail which has a zipped Excel file as an attachment. While extracting the file the identified content_type by the Perl script for this file is application/octet-stream. While extracting the file using the above-mentioned code the file seems to be broken because:
The file is not getting opened through WinZip, WinRAR or 7-Zip.
File size for the file extracted through this script is slightly different than the same file extracted using Outlook.
Kindly provide some input on the issue.

The problem is here
next if $a->{content_type} !~ /octet-stream/i;
zip have content type as application/zip

#NeoNox, Thanks for the response. But the perl system identifies the file as octet-stream only, not with application/zip.
Anyways, I could find the solution.
I could resolve the problem by writing the file in the binary mode(mentioning explicitely as below:
binmode $fh;
Here the file is being writting in the binary mode So I don't get the output as the broken file.

I am finding the same issue.
XLSX files are not seen as attachments.
I am using IMAP.
It will download the email body, any jpgs or pngs etc but does not find the attached xlsx even when in an email that has attachments that are downloaded.

Related

Steganography with Microsoft Word - DOCX

I write a application hide a of string within a .docx file.
A Docx file comprises of a collection of XML files that are contained inside a ZIP archive. So, My program treat that file like a zip file and hide secret string in it.
After research, I found a way to insert data to ZIP archive.
A Secret String is injected after a file section right before the 1st central directory header. After that, a pointer in an end of central directory record is updated to compensate the shift of the central directory header.
My output docx file work fine with typical file archivers (7-zip, WinRAR, File Roller, &c) or file managers (Windows Explorer).
But when I open my output docx file with Microsoft Word it said:
Here is link for input and output file
What step did I wrong or missing?

Howto handle umlauts in Logic App for export to csv

I created a logic app to export some data to a *.csv file.
Data which will be exported contains german umlauts.
I read all the needed values into variables which are then concatenated and added to an array.
Finally I get an array of semicolon separated strings with the values in it.
This result will then be added to an email as file attachment:
All the values are handled correctly in the Logic App and are correct in the *.csv file but as soon I open the csv with Excel, the umlauts are not shown correctly anymore.
Is there a way to create explicitly a file with the correct encoding within the logic app and add the file to the email instead of the ExportString?
Or can I somehow encode the content of the ExportString-Variable?
Any hints?
I have reproduced in my environment and followed below steps to get correct output in CSV file:
My input is:
I have sent the data into CSV table as below and then created a file in file share as below:
Then when i open my file share and download the content from there i got different output as you got:
Then I opened my Azure Storage explorer and downloaded it as below:
When i open in notepad the downloaded file:
I get the correct output, try to do in this way
And when i save it as hello.csv and keep utf-8 with bom like below:
Then I get the correct output in csv as well:

csv file generated with Perl broken

I created a csv file using the perl module Text::CSV_XS.
Here is the relevant code:
open (my $csv_fh, '>', $tmp_file) or die("Unable to open CSV '$tmp_file' for write");
my $csv = Text::CSV_XS->new({'binary' => 1, 'sep_char' => $config->{'csv'}->{'sep_char'}, 'eol' => "\015\012"}) or die(Text::CSV->error_diag());
$csv->print($csv_fh, ["ID", "ASEITE", "ERDAT", "QUELLE", "AUSGABE", "RESSORT", "AUTNR", "NAME", "ANZHLZEIL", "ANZHLZEICH", "UEBER", "TEXTSP", "ART", "BETRAG", "GRUND", "FEST", "STATUS", "SLEVEL"]);
$csv->print($csv_fh, ["A","1","AB","A-5","01","12345","12345","NAME","0","0","Testtext","Testtext2","1","45","","","0",""]);
close $csv_fh;
When i try to open the file using Microsoft Excel i get the message that the filename extension (csv) does not match the format/structure of the file.
I get asked if i trusted the source. After klicking 'ok' i receive the information that there was an error. Again i click 'ok'. After that i can see the csv headline plus the only line of the file. Everything looks as expected.
My question: Why do i get this error message opening the file? What is wrong with the file i created?
When you open a text file whose first 2 characters are "ID" in Excel, it thinks it's a SYLK file, and so gives this warning. This is a very old issue with Excel. See this Microsoft Support page for example. The error will go away if you put quotes around ID or change its case.

Tclsh convert base64 dump into zip file

I have written a Tclsh code that will fetch a zip file content in base64 format through xml-rpc method. I am dumping that base64 data into a file using the following snippet:
#!/usr/bin/tclsh
...
set mybase64Dump [myXmlRpcCallToReturnThisDump]
set zipFilePtr [open "xyz.zip" "w"]
puts $zipFilePtr $mybase64Dump
close $zipFilePte
Zip file was getting generated with XKbytes of size, but when trying to open using 7zip it says, Is not Archive. But I copy pasted the same base64 dump in a online converter. It was giving me a proper extractable zip file.
Is it something I am doing wrongly?
You probably need to configure the output file to be binary, not ascii. The default translation for a newly opened file is "auto", which does system-specific translation of the end-of-line characters, which is not what you want for a .zip file. Configure this using fconfigure on the handle after opening it or by adding the BINARY access flag to the open command.
See http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm and http://www.tcl.tk/man/tcl8.5/TclCmd/fconfigure.htm for details on the syntax.

How to get the content from an uncompressed .docx file by using ifstream.open() and read() methods. office open xml, vc++

I'm trying to build a suffix tree from a .docx file.
So first I unzipped the .docx file and then again created a .docx file with out compressing it. I used ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetLevel(0) method. Here I used C#.
This uncompressed .docx files can be opened without any error.
For the next step I used vc++. By using ifstream.open ("uncompressed.docx", ios::binary ); method I tried to open the file and store the content in a char array by using ifstream.read ( (char *)T, MAX_LENGTH - 1 ) method. But I could not get the actual content of uncompressed.docx file. When I tried to print the content of the char array(T) it printed some formatting tags rather than printing the actual text content of the uncompressed.docx.
I could not figure out what is the actual file that ifstream.open() method opens.It is not the document.xml file.
Please tell me how to get the actual text content from the uncompressed.docx file using VC++.

Resources