View previous topic :: View next topic |
Author |
Message |
earlydaysofsin n00b
Joined: 19 Apr 2002 Posts: 13
|
Posted: Tue May 07, 2002 4:05 pm Post subject: tnef and kmail |
|
|
Has anybody gotten tnef and kmail to work properly? or as a broader question how do you guys decode ms-tnef attachments with kmail? |
|
Back to top |
|
|
mb Guru
Joined: 25 Apr 2002 Posts: 355 Location: Hessen | .de
|
|
Back to top |
|
|
earlydaysofsin n00b
Joined: 19 Apr 2002 Posts: 13
|
Posted: Tue May 07, 2002 4:50 pm Post subject: |
|
|
tried that
i configure with:
./configure --with-qt-dir=/usr/qt/2
but when i compile i get these sorts of errors:
ktnefmain.cpp: In method `void KTNEFMain::setupStatusbar()':
ktnefmain.cpp:96: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
ktnefmain.cpp:97: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
ktnefmain.cpp: In method `void KTNEFMain::loadFile(const QString &)':
ktnefmain.cpp:126: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
ktnefmain.cpp: In method `void KTNEFMain::viewFileAs()':
ktnefmain.cpp:163: no method `KOpenWithHandler::getOpenWithHandler'
ktnefmain.cpp: In method `void KTNEFMain::viewRightButtonPressed(QListViewItem *, const QPoint &, int)':
ktnefmain.cpp:278: warning: unused parameter `class QListViewItem * item'
ktnefmain.cpp: In method `void KTNEFMain::slotShowStatusbar()':
ktnefmain.cpp:325: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
ktnefmain.cpp:326: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
ktnefmain.cpp:328: invalid use of undefined type `class KStatusBar'
/usr/kde/3/include/kmainwindow.h:35: forward declaration of `class KStatusBar'
I understand it is designed for kde 2 but im not sure whether the errors im seeing are related to that. |
|
Back to top |
|
|
earlydaysofsin n00b
Joined: 19 Apr 2002 Posts: 13
|
Posted: Thu May 16, 2002 12:49 pm Post subject: A script for those of you in a hostile M$ environment |
|
|
Where i work all internal messages are encoded with TNEF M$'s email encoding method (on top of MIME). I wanted a filter that when i received such an email the filter would decode the message and repackage any attachments so that i wouldnt have to go through the process of saving them to disk and then using tnef (ktnef does not work with a staright KDE 3 install and even if it did i dont want an extra window to get my attachments damit!) not finding such a filter i wrote one. This script could probably be vastly improved since this is my first perl coding attempt, it works perfectly for me but your mileage may vary. To write this i used some code from amavis.
here it is ... without the spacing .. which seems to have been stripped
#!/usr/bin/perl
use strict;
use MIME::Parser;
use Convert::TNEF;
use MIME::Types;
use MIME::Decoder;
my $text = <STDIN>;
my $TEMPDIR = "/tmp";
my $BOUNDARY = "";
use vars qw($entity);
if (! -e "$TEMPDIR/parts") {
mkdir("$TEMPDIR/parts", 0700);
}
writemsg();
parse_decode();
buildmsg();
sub buildmsg() {
open(MAILFILE, "$TEMPDIR/email.txt") || die ($!);
my @encoded = `ls $TEMPDIR/parts/*`;
chop(@encoded);
my $msg = <MAILFILE>;
while ( ($msg) and ($msg ne "Content-Type: application\/ms-tnef\n"))
{
chomp($msg);
print $msg . "\n";
$BOUNDARY = $msg;
$msg = <MAILFILE>;
}
close(MAILFILE);
my $length = $#encoded;
my $i = 0;
if (defined(@encoded)) {
foreach (@encoded) {
open(ENCFILE, $_);
my $enc = <ENCFILE>;
while ($enc) {
print $enc;
$enc = <ENCFILE>;
}
close(ENCFILE);
unlink $_;
if ($i eq $length) {
print "\n" . $BOUNDARY . "--\n";
} else {
print "\n" . $BOUNDARY . "\n";
}
$i = $i + 1;
}
} else {
print $BOUNDARY . "--\n";
}
unlink "$TEMPDIR/email.txt";
}
sub writemsg() {
open(MAILFILE, ">$TEMPDIR/email.txt") || die ($!);
while ($text) {
print MAILFILE $text;
$text = <STDIN>;
}
close(MAILFILE);
}
sub parse_decode() {
my $fileh = IO::File->new("$TEMPDIR/email.txt") || die ($!);
my ($parser, $filer);
$parser = new MIME::Parser;
$filer = MIME::Parser::FileInto->new("$TEMPDIR/parts");
$filer->ignore_filename(1);
$parser->filer($filer);
$parser->extract_nested_messages("NEST");
$entity = $parser->parse($fileh);
$fileh->seek(0,0);
my @parts = `ls $TEMPDIR/parts/*.dat`;
chop(@parts);
foreach (@parts) {
decompose_part($_);
}
$parser->filer->purge;
my @extracted = `ls $TEMPDIR/parts`;
chop(@extracted);
foreach (@extracted) {
my $fullname = $TEMPDIR . "/parts/" . $_;
my $encodedname = $TEMPDIR . "/parts/enc." . $_;
my $types = MIME::Types->new;
my MIME::Type $mime = $types->mimeTypeOf($_);
open(ATFILE, "$fullname");
open(ENCFILE, ">$encodedname");
if (defined($mime)) {
if ($mime->isBinary) {
print ENCFILE "Content-Type: " . $mime . ";\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: base64\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'base64';
$decoder->encode(\*ATFILE, \*ENCFILE);
} else {
print ENCFILE "Content-Type: " . $mime . ";\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: quoted-printable\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'quoted-printable';
$decoder->encode(\*ATFILE, \*ENCFILE);
}
} else {
print ENCFILE "Content-Type: application\octet-stream;\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: quoted-printable\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'quoted-printable';
$decoder->encode(\*ATFILE, \*ENCFILE);
}
close(ATFILE);
close(ENCFILE);
unlink $fullname;
}
}
sub decompose_part(@) {
my $filea = shift;
#my $tnef = Convert::TNEF->read_in($part,{ignore_checksum=>"true",debug=>"true"});
my $tnef = Convert::TNEF->read_in($filea,{ignore_checksum=>"true"});
if ($tnef) {
for ($tnef->attachments) {
my $filename = $_->longname;
my $newpart = "$TEMPDIR/parts/" . $filename;
open(OUTPART, ">$newpart") || die ($!);
print OUTPART $_->data;
close(OUTPART);
}
$tnef->purge;
}
} |
|
Back to top |
|
|
tomte Tux's lil' helper
Joined: 08 May 2002 Posts: 122
|
Posted: Thu May 16, 2002 2:14 pm Post subject: Re: A script for those of you in a hostile M$ environment |
|
|
earlydaysofsin wrote: |
here it is ... without the spacing .. which seems to have been stripped
|
next time, try
element of BBCode; perl hurts my eyes, even more if not properly indented
kind regards,
Tom |
|
Back to top |
|
|
earlydaysofsin n00b
Joined: 19 Apr 2002 Posts: 13
|
Posted: Mon May 20, 2002 11:23 am Post subject: for those that have enough trouble with perl code |
|
|
thanks tomte
Code: |
#!/usr/bin/perl
use strict;
use MIME::Parser;
use Convert::TNEF;
use MIME::Types;
use MIME::Decoder;
my $text = <STDIN>;
my $TEMPDIR = "/tmp";
my $BOUNDARY = "";
use vars qw($entity);
if (! -e "$TEMPDIR/parts") {
mkdir("$TEMPDIR/parts", 0700);
}
writemsg();
parse_decode();
buildmsg();
sub buildmsg() {
open(MAILFILE, "$TEMPDIR/email.txt") || die ($!);
my @encoded = `ls $TEMPDIR/parts/*`;
chop(@encoded);
my $msg = <MAILFILE>;
while ( ($msg) and ($msg ne "Content-Type: application\/ms-tnef\n"))
{
chomp($msg);
print $msg . "\n";
$BOUNDARY = $msg;
$msg = <MAILFILE>;
}
close(MAILFILE);
my $length = $#encoded;
my $i = 0;
if (defined(@encoded)) {
foreach (@encoded) {
open(ENCFILE, $_);
my $enc = <ENCFILE>;
while ($enc) {
print $enc;
$enc = <ENCFILE>;
}
close(ENCFILE);
unlink $_;
if ($i eq $length) {
print "\n" . $BOUNDARY . "--\n";
} else {
print "\n" . $BOUNDARY . "\n";
}
$i = $i + 1;
}
} else {
print $BOUNDARY . "--\n";
}
unlink "$TEMPDIR/email.txt";
}
sub writemsg() {
open(MAILFILE, ">$TEMPDIR/email.txt") || die ($!);
while ($text) {
print MAILFILE $text;
$text = <STDIN>;
}
close(MAILFILE);
}
sub parse_decode() {
my $fileh = IO::File->new("$TEMPDIR/email.txt") || die ($!);
my ($parser, $filer);
$parser = new MIME::Parser;
$filer = MIME::Parser::FileInto->new("$TEMPDIR/parts");
$filer->ignore_filename(1);
$parser->filer($filer);
$parser->extract_nested_messages("NEST");
$entity = $parser->parse($fileh);
$fileh->seek(0,0);
my @parts = `ls $TEMPDIR/parts/*.dat`;
chop(@parts);
foreach (@parts) {
decompose_part($_);
}
$parser->filer->purge;
my @extracted = `ls $TEMPDIR/parts`;
chop(@extracted);
foreach (@extracted) {
my $fullname = $TEMPDIR . "/parts/" . $_;
my $encodedname = $TEMPDIR . "/parts/enc." . $_;
my $types = MIME::Types->new;
my MIME::Type $mime = $types->mimeTypeOf($_);
open(ATFILE, "$fullname");
open(ENCFILE, ">$encodedname");
if (defined($mime)) {
if ($mime->isBinary) {
print ENCFILE "Content-Type: " . $mime . ";\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: base64\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'base64';
$decoder->encode(\*ATFILE, \*ENCFILE);
} else {
print ENCFILE "Content-Type: " . $mime . ";\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: quoted-printable\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'quoted-printable';
$decoder->encode(\*ATFILE, \*ENCFILE);
}
} else {
print ENCFILE "Content-Type: application\octet-stream;\n";
print ENCFILE " name=\"" . $_ . "\"\n";
print ENCFILE "Content-Transfer-Encoding: quoted-printable\n";
print ENCFILE "Content-Disposition: attachment;\n";
print ENCFILE " filename=\"" . $_ ."\"\n\n";
my $decoder = new MIME::Decoder 'quoted-printable';
$decoder->encode(\*ATFILE, \*ENCFILE);
}
close(ATFILE);
close(ENCFILE);
unlink $fullname;
}
}
sub decompose_part(@) {
my $filea = shift;
#my $tnef = Convert::TNEF->read_in($part,{ignore_checksum=>"true",debug=>"true"});
my $tnef = Convert::TNEF->read_in($filea,{ignore_checksum=>"true"});
if ($tnef) {
for ($tnef->attachments) {
my $filename = $_->longname;
my $newpart = "$TEMPDIR/parts/" . $filename;
open(OUTPART, ">$newpart") || die ($!);
print OUTPART $_->data;
close(OUTPART);
}
$tnef->purge;
}
}
|
|
|
Back to top |
|
|
turbobri n00b
Joined: 07 Oct 2002 Posts: 14
|
Posted: Thu Oct 24, 2002 4:50 am Post subject: script not working |
|
|
earlydaysofsin,
Your script isn't working that great for me.
I always get a message:
Quote: | ls: /tmp/parts/*: No such file or directory |
Any chance you have enhanced the script since last posting it? I am also wondering how I would use this with Postfix to convert incoming email on the fly, and how I might be able to convert all my existing emails (stored in maildir format). |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|