Torsmo [I]

Jan 发表于 2005-03-11 14:07:44

torsmo是一个类似于gdesklets的软件。在我的桌面上右边那个用来显示gmail/bloglines/weather的工具就是 torsmo. 我将会贴出一系列文章来说明torsmo的配置方法。简单的配置我就不说了,.torsmorc里面有很好的注释. 我想要说的是如何定制适合自己的个性化的torsmo.

torsmo的灵活性非常强,通过和定制脚本的配合可以做成许多事情。这里我贴出自己用的
几个脚本。我把这些脚本都放在~/.torsmo里面,而.torsmorc是~/.torsmo/torsmorc的一
个软链接。

首先是检查Gmail的新邮件信息的脚本,如果有新邮件,还可以显示出邮件标题。

~/.torsmo/gmail.pl: 通过Gmail的API得到邮箱状态信息

#!/usr/bin/perl
## gmail.pl

#find this two lib on CPAN
use Mail::Webmail::Gmail;
use GMail::Checker;

my greatest_ = "YOUR_ADDR"; # your Gmail username
my $password = "YOUR_PASS"; # your Gmail password
my $gmailfile = "/home/XXX/.torsmo/gmail.txt";
my $newmessages = 0;
my @subjects = ();

my $gwrapper = new GMail::Checker();
$gwrapper->login(greatest , $password);

my ($totalmessages, $usedspace) = $gwrapper->get_msg_nb_size();
$gwrapper->close();

my $gmail = Mail::Webmail::Gmail->new(username => greatest , password =>
$password, encrypt_session => 1);
my ($usage, $capacity, $usagep) = $gmail->size_usage();
my $messages = $gmail->get_messages(label => $Mail::Webmail::Gmail::FOLDERS{
'INBOX' });

foreach ( @{ $messages } ) {
   if ( $_->{ 'new' } ) {
       $newmessages += 1;
       my $subject = $_->{ 'subject' };
       $subject =~ s/<(.*?)>//gi; # remove tags
       push(@subjects, $subject);
   }
}

open(FD, "> " . $gmailfile) or die("Could not open file.\n");
print FD "totalmessages=" . $totalmessages . "\n";
print FD "newmessages=" . $newmessages . "\n";
print FD "status=Using " . $usage . " (" . $usagep . ") of " . $capacity . "\n";
for($i=0; $i<=$#subjects; $i++) {
   print FD $subjects[$i] . "\n";
}
close(FD);

~/.torsmo/gmail_extract.pl: 提取信息的脚本,为torsmo所调用

#!/usr/bin/perl
# gmail_extract.pl

my $numArgs = $#ARGV+1;

if($numArgs != 1) {
   die ("Usage error: gmail_extract.pl [info]\n");
   exit;
}
else {
   my $file = "/home/XXX/.torsmo/gmail.txt";
   my $arg = $ARGV[0];
   open (HANDLE, $file) or die ("Could not open file.");
   @LINES = ;

   if ($arg eq "newsubjects") {
       $line = $LINES[1];
       my ($foo, $newmessages) = split(/=/, $line);
       if($newmessages > 0) {
           for($i=3; $i<=$#LINES && $i < 12; $i++) {
               my $num = $i-2;
               my $sub = $LINES[$i];

               # truncate long subjects so it will not
               # autoexpand the tormso window
               if(length($sub) >= 40) {
                   my $temp = substr($sub, 0, 40);
                   $sub = $temp . "...\n";
               }
               print " " . $num . ". " . $sub;
           }
           if($#LINES > 11) {
               print " Check mailbox to see more ...";
           }
       }
   }

   # how many total message do I have?
   if($arg eq "totalmessages") {
       $line = $LINES[0];
       my ($foo, $total) = split(/=/, $line);
       $total =~ s/[\r\n]//g; # remove \n
       print "There are " . $total . " messages\n";
  }

   # how many new messages do I have?
   if($arg eq "newmessages") {
       $line = $LINES[1];
       my ($foo, $new) = split(/=/, $line);
       $new =~ s/[\r\n]//g; # remove \n
       if($new == 0) { print "There are no new messages\n"; }
       elsif($new == 1) { print "There is one new message\n"; }
       else { print "There are " . $new . " new messages\n"; }
   }

   # usage status
   if($arg eq "status") {
       $line = $LINES[2];
       my ($foo, $retval) = split(/=/, $line);

   # usage status
   if($arg eq "status") {
       $line = $LINES[2];
       my ($foo, $retval) = split(/=/, $line);
       print $retval;
   }

   close (HANDLE);
}

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定