ThinkingRock Forum

To go back to http://www.trgtd.com.au
It is currently Tue May 21, 2013 2:36 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Thunderbird integration
PostPosted: Sat Oct 18, 2008 12:06 pm 
Offline

Joined: Tue Jun 10, 2008 5:37 am
Posts: 4
There's a nice thunderbird addon named "view source with" at
https://addons.mozilla.org/de/thunderbird/addon/394
Basically, you can assign a keyboard shortcut to run any program on the source of the current email.

Thus, I wrote:

Code:
#!/usr/bin/perl -w
use MIME::Parser;
use Fcntl ':flock';


use Tk;   
use Tk::Dialog;



if (@ARGV < 1 ){
    die "please provide file!";
}

$file=shift(@ARGV);
$outfile="/home/max/tr/thoughts.txt";

open IN, $file or die "could not open  $file!";

while ($line=<IN>){
    if($line=~/^Subject: (.*)/){
   $subject=$1;
    }
    if($line=~/^Date: (.*)/){
   $date=$1;
    }
    if($line=~/^From: (.*)/){
   $from=$1;
    }
    if(defined $subject && defined $date && defined $from){
   last;
    }
}
close IN;
unlink $file;


$outstring="email: $subject; $from; $date\temail";

#loop borrowed from
#http://www.gnu.org/software/gnats/mimedecode.html

while ($outstring =~ m/=\?[^?]+\?(.)\?([^?]*)\?=/)
{
    $encoding   = $1;
    $txt        = $2;
    $str_before = $`;
    $str_after  = $';
   
    # Base64
    if ($encoding =~ /b/i)
    {
   require MIME::Base64;
   MIME::Base64->import(decode_base64);
   $txt = decode_base64($txt);
    }
   
    # QP
    elsif ($encoding =~ /q/i)
    {
   require MIME::QuotedPrint;
   MIME::QuotedPrint->import(decode_qp);
   $txt = decode_qp($txt);
    }
   
    $outstring = $str_before . $txt . $str_after;
}
# The decode above does not do underline-to-space translation:
$outstring =~ tr/_/ /;


open OUT, ">>$outfile" or die "could not open file $outfile!";
unless (flock OUT, LOCK_EX | LOCK_NB) {
    warn "File $outfile already locked; waiting...\n";
    flock OUT, LOCK_EX or die "could not lock file $outfile\n";
}
print OUT "$outstring\n";
close OUT;

my $mw = MainWindow->new;
$mw->withdraw();
my $dialog = $mw->Dialog (-title => "Info",
           -buttons => ["Ok"],
           -text=>$outstring);
my $item = $dialog->Show();

exit 0;



This collects subject, sender and date for every email that I want to be an action in thinkingrock. After having processed my inbox, I can import the thoughts file into thinkingrock and delete it afterwards.

Pretty handy and the first time I feel comfortable handling email tasks with TR. (Doing this manually would just take too much time.)

Hope, it is of some help for somebody ;-)

EDIT: New version that uses a TK dialog and file locking


Last edited by clarklevel on Tue Oct 21, 2008 9:23 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 10:16 am 
Offline

Joined: Tue Oct 02, 2007 6:39 am
Posts: 28
Hi Clarklevel,

I am interested in utilising this, I am using

Product Version: ThinkingRock 2.0.1
Java: 1.6.0_06; Java HotSpot(TM) Client VM 10.0-b22
System: Windows XP version 5.1 running on x86; Cp1252; en_NZ (tr)
Thunderbird 2.0.0.17 & VeiwSourceWith 0.3

Would you please supply the steps that I would need to impliment the above code so that I am able to utalize it with my system.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 11:11 am 
Offline

Joined: Tue Jun 10, 2008 5:37 am
Posts: 4
BusinessSage wrote:
Would you please supply the steps that I would need to impliment the above code so that I am able to utalize it with my system.


Since you're using windows, you will need to get perl (that's the programming language the script that I posted is written in).
Maybe http://win32.perl.org/wiki/ is a good start.


Then, you have to change the line
Code:
$outfile="/home/max/tr/thoughts.txt";

to a place where you want the thoughts.txt to be.


You won't need.
Code:
system("zenity --info  --title email2thought --text="$outstring"");

That only works on linux and displays a popup confirming what just has been saved.

What you have to put in the "view source with" plugin is probably something like
Code:
c:\path\to\perl.exe c:\path\to\the-script.pl


I hope that this puts you onto the right path - it's a bit difficult to be more detailed since I don't have a windows computer here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2008 9:25 am 
Offline

Joined: Tue Jun 10, 2008 5:37 am
Posts: 4
I edited the initial post to post a new version that uses file locking and a Tk dialog.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2008 10:38 am 
Offline

Joined: Tue Oct 02, 2007 6:39 am
Posts: 28
Hi clarklevel,

I have downloaded perl (two flavours) and will install over the next day or two as time allows.

Will post how I get on.

Thanks


Top
 Profile  
 
 Post subject: Modules needed
PostPosted: Sun Oct 26, 2008 1:06 pm 
Offline

Joined: Sun Oct 26, 2008 12:52 pm
Posts: 1
The perl module MIME::Parser was not installed on my Ubuntu.

I found MIME::Parser on CPAN as part of MIME-tools http://search.cpan.org/~doneill/MIME-tools-5.427/

For Ubuntu-users: install the libmime-perl package with synaptic (or whatever you prefer).

Now it works - thanks for sharing your code! :D

But what do you think about editing the outstring in the Tk-window - sometimes the mail subject does not reflect my thought. :roll:

I've replaced the code at the end of your script from
Code:
open OUT, ">>$outfile" or die "could not open file $outfile!";
unless (flock OUT, LOCK_EX | LOCK_NB) {
    warn "File $outfile already locked; waiting...\n";
    flock OUT, LOCK_EX or die "could not lock file $outfile\n";
}
print OUT "$outstring\n";
close OUT;

my $mw = MainWindow->new;
$mw->withdraw();
my $dialog = $mw->Dialog (-title => "Info",
           -buttons => ["Ok"],
           -text=>$outstring);
my $item = $dialog->Show();

exit 0;

to
Code:
my $mw = MainWindow->new;

    $mw->geometry("+20+60");
    $mw->Label(-text => 'Thought')->pack;
    my $thought = $mw->Entry(-width => 120);
    $thought->insert(0, $outstring);
    $thought->pack;
    $mw->Button(
        -text => 'Save Thought',
        -command => sub { save_thought($thought) }
    )->pack;
    $mw->Button(
        -text    => 'Quit',
        -command => sub { exit }
    )->pack;

    MainLoop;

    sub save_thought {
        my $thought = shift;
        $outstring = $thought->get;
        $mw->Hide();

open OUT, ">>$outfile" or die "could not open file $outfile!";
unless (flock OUT, LOCK_EX | LOCK_NB) {
    warn "File $outfile already locked; waiting...\n";
    flock OUT, LOCK_EX or die "could not lock file $outfile\n";
}
print OUT "$outstring\n";
close OUT;

    }

exit 0;

(extra indentation = my changes)

Hope you like it. Use at own risk. :wink:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group