Hi All,
I'm working on a Plugin for downloading messages either in the message list of while viewing a message. I ran into a problem with some of the downloaded messages though. HTML messages seem to have these ='s and =20's and some of the HTML source show once I have it downloaded. The plugin basically uses some borrowed code from GMail::Messages and GT::FileMan::Commands.pm to read in the raw message (or messages) from disk and send them/it to the browser (tarred and ziped if multiple messages).
Here is some of the output of a message:
Try adding some addresses to our integrated addre= ss book. If you give a user a nickname,
then when you compose a message, you= can just enter in the nickname.
Create yourself a signature, this will get append= ed to the bottom of all your outgoing mail.
From the options screen you can set up a wide var= iety of features to get
Gossamer Mail working just the way you want.
Be sure to try adding a Remote POP account! This = lets you pull in mail from other accounts
into Gossamer Mail. Click on Check E= mail to get the email once you have setup a POP account.
If you have any questions at all about the demo, ple= ase visit the support= forum, or
contact = us for more information.
Cheers,
Alex Krohn
Gossamer Threads Inc.
</HTML
And here is a snippet of the code I use to make up the messages:
#----------------------------------------------------------------
# download a message or messages
my $self = shift;
my @id = $IN->param('msgtrack_id') or return {message => 'DWNLDMSG_NOIDS'};
my $compression = $USER->{opts}->{download_messages}->{compression_type} || 'tar';
my $mode = 'auto';
if ($#id == 0 && !$USER->{opts}->{download_messages}->{compress_single}) {
my $file = $self->_file($id[0]);
return $self->_send_to_browser($file->{path}, $mode, "$file->{subject}-$file->{id}.eml");
}
my $tempfile = new GT::TempFile;
if ($compression eq 'zip' and $HAVE_AZIP) {
my $error = $self->_zip_process("$$tempfile.zip", \@id);
die "Failed to process zip" if ($error);
} else {
$self->_tar_process("$$tempfile.$compression", \@id);
}
$self->_send_to_browser("$$tempfile.$compression", $mode, "Messages.$compression");
return {message => 'DWNLDMSG_SUCCESS'}
}
sub _zip_process {
#--------------------------------------------------------------
# Create a .zip file
my ($self, $to, $ids) = @_;
require Archive::Zip::Tree;
my $zip = Archive::Zip->new();
my $member;
foreach my $id (@$ids) {
my $file = $self->_file($id);
next unless -f $file->{path};
$member = $zip->addFile($file->{path}, "Messages/$file->{subject}-$file->{id}.eml") or die "$!";
}
return $zip->writeToFileNamed($to) ? "$!" : 0;
}
sub _tar_process {
#--------------------------------------------------------------
# Create tar file
my ($self, $to, $ids) = @_;
# Make sure tar file goes out of scope and cleans up temp files
{
require GT::Tar;
my $tar = new GT::Tar($to) or die "Failed to create GT::Tar file";
foreach my $id (@$ids) {
my $file = $self->_file($id);
$tar->add_file($file->{path});
my $f = $tar->get_file($file->{path});
$f->{name} = "Messages/$file->{subject}-$file->{id}.eml";
}
$tar->write("$to");
}
}
sub _send_to_browser {
#----------------------------------------------------------------
# send the contents of a file to browser for downloading
my $self = shift;
my $send_file = shift;
my $mode = shift;
my $name = shift;
if ($mode eq 'auto') { $mode = (-T $send_file) ? 'ascii' : 'binary'; }
open SENDFILE, $send_file or die "Failed to open sendfile for output to browser: $!";
my $file_size = -s $send_file;
if (!$name) { ($name) = $send_file =~ m,/([^/]+)$,; }
print $IN->header( '-type' => 'application/download',
'-Content-Length' => $file_size,
'-Content-Transfer-Encoding' => $mode,
'-Content-Disposition' => \"attachment; filename=\"$name\"");
binmode STDOUT if ($^O eq 'MSWin32');
binmode SENDFILE;
my $buffer;
while (read(SENDFILE, $buffer, 500000)){
if ($mode eq 'ascii') { $buffer =~ s,\r\n,\n,g; }
print $buffer;
}
close SENDFILE;
return 1;
}
I'm not sure where to start looking at this point. Is it 1) A problem with how OutlookExpress is decoding the messages? 2) A problem with my code to grab the message or 3) A problem with how the message was generated to begin with?
Any help would be greatly appreciated. I've included the tar with all the code and files if you need it. The Plugin will install but it's still missing some parts/pieces to make it work off the shelf so it's not a good idea to install it as is.
Thanks,
Charlie
I'm working on a Plugin for downloading messages either in the message list of while viewing a message. I ran into a problem with some of the downloaded messages though. HTML messages seem to have these ='s and =20's and some of the HTML source show once I have it downloaded. The plugin basically uses some borrowed code from GMail::Messages and GT::FileMan::Commands.pm to read in the raw message (or messages) from disk and send them/it to the browser (tarred and ziped if multiple messages).
Here is some of the output of a message:
Code:
Click on Folders to see a list of your current fo= lders. You now have one click trash buttons! Try adding some addresses to our integrated addre= ss book. If you give a user a nickname,
then when you compose a message, you= can just enter in the nickname.
Create yourself a signature, this will get append= ed to the bottom of all your outgoing mail.
From the options screen you can set up a wide var= iety of features to get
Gossamer Mail working just the way you want.
Be sure to try adding a Remote POP account! This = lets you pull in mail from other accounts
into Gossamer Mail. Click on Check E= mail to get the email once you have setup a POP account.
If you have any questions at all about the demo, ple= ase visit the support= forum, or
contact = us for more information.
Cheers,
Alex Krohn
Gossamer Threads Inc.
</HTML
And here is a snippet of the code I use to make up the messages:
Code:
sub download { #----------------------------------------------------------------
# download a message or messages
my $self = shift;
my @id = $IN->param('msgtrack_id') or return {message => 'DWNLDMSG_NOIDS'};
my $compression = $USER->{opts}->{download_messages}->{compression_type} || 'tar';
my $mode = 'auto';
if ($#id == 0 && !$USER->{opts}->{download_messages}->{compress_single}) {
my $file = $self->_file($id[0]);
return $self->_send_to_browser($file->{path}, $mode, "$file->{subject}-$file->{id}.eml");
}
my $tempfile = new GT::TempFile;
if ($compression eq 'zip' and $HAVE_AZIP) {
my $error = $self->_zip_process("$$tempfile.zip", \@id);
die "Failed to process zip" if ($error);
} else {
$self->_tar_process("$$tempfile.$compression", \@id);
}
$self->_send_to_browser("$$tempfile.$compression", $mode, "Messages.$compression");
return {message => 'DWNLDMSG_SUCCESS'}
}
sub _zip_process {
#--------------------------------------------------------------
# Create a .zip file
my ($self, $to, $ids) = @_;
require Archive::Zip::Tree;
my $zip = Archive::Zip->new();
my $member;
foreach my $id (@$ids) {
my $file = $self->_file($id);
next unless -f $file->{path};
$member = $zip->addFile($file->{path}, "Messages/$file->{subject}-$file->{id}.eml") or die "$!";
}
return $zip->writeToFileNamed($to) ? "$!" : 0;
}
sub _tar_process {
#--------------------------------------------------------------
# Create tar file
my ($self, $to, $ids) = @_;
# Make sure tar file goes out of scope and cleans up temp files
{
require GT::Tar;
my $tar = new GT::Tar($to) or die "Failed to create GT::Tar file";
foreach my $id (@$ids) {
my $file = $self->_file($id);
$tar->add_file($file->{path});
my $f = $tar->get_file($file->{path});
$f->{name} = "Messages/$file->{subject}-$file->{id}.eml";
}
$tar->write("$to");
}
}
sub _send_to_browser {
#----------------------------------------------------------------
# send the contents of a file to browser for downloading
my $self = shift;
my $send_file = shift;
my $mode = shift;
my $name = shift;
if ($mode eq 'auto') { $mode = (-T $send_file) ? 'ascii' : 'binary'; }
open SENDFILE, $send_file or die "Failed to open sendfile for output to browser: $!";
my $file_size = -s $send_file;
if (!$name) { ($name) = $send_file =~ m,/([^/]+)$,; }
print $IN->header( '-type' => 'application/download',
'-Content-Length' => $file_size,
'-Content-Transfer-Encoding' => $mode,
'-Content-Disposition' => \"attachment; filename=\"$name\"");
binmode STDOUT if ($^O eq 'MSWin32');
binmode SENDFILE;
my $buffer;
while (read(SENDFILE, $buffer, 500000)){
if ($mode eq 'ascii') { $buffer =~ s,\r\n,\n,g; }
print $buffer;
}
close SENDFILE;
return 1;
}
I'm not sure where to start looking at this point. Is it 1) A problem with how OutlookExpress is decoding the messages? 2) A problem with my code to grab the message or 3) A problem with how the message was generated to begin with?
Any help would be greatly appreciated. I've included the tar with all the code and files if you need it. The Plugin will install but it's still missing some parts/pieces to make it work off the shelf so it's not a good idea to install it as is.
Thanks,
Charlie