473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problems with decoding: resulting image is corrupt

Hello!
My resulting image har nearly same size of original (but not exact) and the
nu.jpg can be shown,
but it is modified so much, that it look totally different.... why? what to
do?
Greetings Bjorn!

============================
use strict;
use Net::POP3;
use MIME::Base64;

my $username = 'user1';
my $password = 'userpw';
my $pop = Net::POP3->new('mailme.org', Timeout => 60);

if ($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $mailfile = 'mail'.$msgnum.".txt";
open(M, ">$mailfile") or die "Error\tCouldn't open $mailfile, $!";
print "msg $msgnum\n";
my $msg = $pop->get($msgnum);
#print @$msg;
print M @$msg;
#$pop->delete($msgnum);
close(M);
}
}

$pop->quit;
my $b64str;
open(UD, ">nu.jpg") or die "$!";

open(IND, "<mail2.txt") or die "$!";
my $part2decode = 0;
my $line = 0;

while(<IND>) {
if ( /Content-Disposition/i ) {
$part2decode++;
}
if ( $part2decode ) {
$line++;
}
if ( /Boundary/ ) {
$part2decode = 0;
}
if ( $part2decode && $line > 1 ) {
my $encoded = $_;

my $decoded = decode_base64($encoded);
print UD $decoded;
}
}
close(UD);
close(IND);


Jul 19 '05 #1
2 4232
Bjorn Jensen wrote:
My resulting image har nearly same size of original (but not exact) and the
nu.jpg can be shown,
but it is modified so much, that it look totally different.... why?
You have to use binmode() when dealing with binary files.
open(UD, ">nu.jpg") or die "$!";


open(UD, '>', 'nu.jpg') or die "Cannot create nu.jpg: $!";
binmode(UD);

-Joe
Jul 19 '05 #2
Hi again!
Oh, of course - I tried binary(UD) yesterday but this gave error.'
Now it works - thanks!
Now I'll look for a better way to extract attachments.
I try to figure out, how to use
Email::MIME::Attachment::Stripper;
but have no success...
The documentation is spare.
Any good example, that I can use for expanding my case below?

Greetings Bjørn

"Bjorn Jensen" <b.*******************@gmxandthis.net> wrote in message
news:42***********************@nntp03.dk.telia.net ...
Hello!
My resulting image har nearly same size of original (but not exact) and the nu.jpg can be shown,
but it is modified so much, that it look totally different.... why? what to do?
Greetings Bjorn!

============================
use strict;
use Net::POP3;
use MIME::Base64;

my $username = 'user1';
my $password = 'userpw';
my $pop = Net::POP3->new('mailme.org', Timeout => 60);

if ($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $mailfile = 'mail'.$msgnum.".txt";
open(M, ">$mailfile") or die "Error\tCouldn't open $mailfile, $!";
print "msg $msgnum\n";
my $msg = $pop->get($msgnum);
#print @$msg;
print M @$msg;
#$pop->delete($msgnum);
close(M);
}
}

$pop->quit;
my $b64str;
open(UD, ">nu.jpg") or die "$!";

open(IND, "<mail2.txt") or die "$!";
my $part2decode = 0;
my $line = 0;

while(<IND>) {
if ( /Content-Disposition/i ) {
$part2decode++;
}
if ( $part2decode ) {
$line++;
}
if ( /Boundary/ ) {
$part2decode = 0;
}
if ( $part2decode && $line > 1 ) {
my $encoded = $_;

my $decoded = decode_base64($encoded);
print UD $decoded;
}
}
close(UD);
close(IND);


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Williams | last post by:
Hello everyone, my name is Tom W. And, I am new to the list, and have been using Python for about a year now. Anyway, I got a question! I am trying to decode MIME (base64) email from a POP3...
1
by: Thomas Williams | last post by:
Thanks, I tried it and it stop at: f = file("mail.txt") with the error message. TypeError: 'str' object is not callable Tom Williams
0
by: BRAINIAC | last post by:
I am trying to process JPEG images using PIL 1.1.4 with Python 2.2.3. GIF and PNG are working fine. I am using jpeg-6b and all my other software using libjpeg work fine. I am thinking you need...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
1
by: Slade | last post by:
Hi, I'm trying to use POST an image to a web page with WebRequest/WebResponse. Only problem is that I must be making an error somewhere in the encoding/decoding process. I've pasted below a bit...
2
by: Adam | last post by:
I have extensively searched for a solution. Below is my code that is contained in an aspx. When my browser hits this aspx, I just get the standard broken image picture. I know the data is the...
0
by: guilligan.geo | last post by:
Hello, I'm trying to create an addin for Outlook 2002 using the one provided in the demo of win32com as a starting point. I've been able to do my addin and test it if I go the "standard" way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.