QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3141|回复: 3

让torsmo也能查看gmail

[复制链接]
发表于 2005-7-22 13:39:15 | 显示全部楼层 |阅读模式
刚从gentoo forums看来的,给大家翻译一下 :D

效果图:


要求:1.torsmo
         2.gmail帐号,别说你没有,公社里发gmail帐号的比发传单的还多。

废话完了,下面开始动工。

1.先安装好Mail-Webmail-GmailGmail-Checker

  安装很简单,只要perl Makefile.pl && make && make test && make install就可以了。

2.建立一个叫gmail.pl的文件,放在~/.torsmo目录下(事实上目录可以自己定的,无所谓)。并chmod +x gmail.pl 。gmail.pl内容如下:
[code:1]#!/usr/bin/perl
# gmail.pl

use Mail::Webmail::Gmail;
use GMail::Checker;

my $username = "user.name"; #你的Gmail用户名
my $password = "password"; # 你的Gmail密码
my $gmailfile = "/home/username/.torsmo/gmail.txt";#存放gmail检查信息的地址文件,和gmail.pl放在一块就是了。
my $newmessages = 0;
my @subjects = ();

my $gwrapper = new GMail::Checker();
$gwrapper->login($username, $password);
my ($totalmessages, $usedspace) = $gwrapper->get_msg_nb_size();
$gwrapper->close();

my $gmail = Mail::Webmail::Gmail->new(
   username => $username, 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 <b> 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);[/code:1]

3.建立一个gmail_extract.pl文件,同样放在和gmail.pl的相同目录,并写入:
[code:1]#!/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/username/.torsmo/gmail.txt"; #请指定gmail.txt的地址。
   my $arg = $ARGV[0];
   open (HANDLE, $file) or die ("Could not open file.");
   @LINES = <HANDLE>;

   if ($arg eq "newsubjects") {
      $line = $LINES[1];
      my ($foo, $newmessages) = split(/=/, $line);
      if($newmessages > 0) {
         for($i=3; $i<=$#LINES; $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;
         }
      }
   }

   # 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);
      print $retval;
   }

   close (HANDLE);
}
[/code:1]

4.然后把这一段加入torsmo的配置文件(~/.torsmorc)
[code:1]GMAIL:
${color grey}Status      : $color${execi 300 perl ~/.torsmo/gmail_extract.pl status}
${color grey}Messages    : $color${execi 300 perl ~/.torsmo/gmail_extract.pl totalmessages}
${color grey}New         : $color${execi 300 perl ~/.torsmo/gmail_extract.pl newmessages}

$color${execi 300 perl ~/.torsmo/gmail_extract.pl newsubjects}[/code:1]

5.事实上做到这里并不能使torsmo查阅gmail邮件,必须通过命令perl ~/.torsmo/gmail.pl才能执行。为了让torsmo能够看到新邮件信息并每隔10分钟刷新一次,可以在/etc/crontab中加入这样一行:
[code:1]0-59/10 * * * * root     perl /home/username/.torsmo/gmail.pl 2>&1 #其中的10即为每10分钟查看一次,可以自己更换。更为详细的,翻老贴查看关于cron的使用方法吧![/code:1]

好了,这样就OK了,重启一下应该没什么问题了。

另外:我的torsmo无法显示中文,弄得gmail中文邮件显示不了。不知道怎么写torsmo的中文字体设置,谁给个sample?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2005-7-22 14:30:44 | 显示全部楼层
路过,看看
回复

使用道具 举报

发表于 2005-7-26 21:39:40 | 显示全部楼层
gmail不支持pop3么?
我记得好像有选的,可以启动或关闭pop3功能
回复

使用道具 举报

 楼主| 发表于 2005-7-27 10:17:43 | 显示全部楼层
gmail支持POP3,用torsmo并不是去收发gmail邮件,而是预览新邮件,告诉你有新信息了。
而且要是换成每分钟刷一次,gmail刷个3G大不是什么问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-26 22:58 , Processed in 0.087811 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表