よろずや

FreeBSD メモ

gotmail を使う

Hotmail からメールを取得するツール,gotmail なるものを教えてもらう.試行錯誤 の末,なんとかうごかせるようになった(しかし,Hotmail の言語設定を英語にすれ ば↓のパッチは不要な気がする).まぁ,なにはともあれ,便利なので良しとしよう….

username=username
password=password
domain=hotmail.com
save-to-login
only-new
folder-dir=/home/lambda/.hotmail
# Inbox じゃなくて↓これ.
folders=受信トレイ
retry-limit=3

.gotmailrc

*** gotmail	Fri Mar 14 09:12:14 2003
--- gotmail.jp	Sat May 31 08:09:51 2003
***************
*** 37,42 ****
--- 37,44 ----
  use FileHandle;
  use strict;
  
+ use Jcode;
+ 
  # Signal handlers:
  $SIG{INT} = $SIG{__DIE__} =
  	sub {
***************
*** 232,238 ****
  		} elsif ($_ =~ /^forward(ing-email)?=(.+)$/i) {
  			$resend_address = $2;
  		} elsif ($_ =~ /^folders=(.+)$/i) {
! 			@conf_folders = split(/ *, */, $1);
  		} elsif ($_ =~ /^folder[_-]dir(ectory)?=(.+)$/i) {
  			$conf_folder_directory = $2;
  			if ($conf_folder_directory !~ /\/$/) {
--- 234,241 ----
  		} elsif ($_ =~ /^forward(ing-email)?=(.+)$/i) {
  			$resend_address = $2;
  		} elsif ($_ =~ /^folders=(.+)$/i) {
! 		        my $tmp = Jcode->new($1)->euc;
! 			@conf_folders = split(/ *, */, $tmp);
  		} elsif ($_ =~ /^folder[_-]dir(ectory)?=(.+)$/i) {
  			$conf_folder_directory = $2;
  			if ($conf_folder_directory !~ /\/$/) {
***************
*** 782,787 ****
--- 785,791 ----
  {
  	my($url, $add_mboxheader, $folder) = @_;
  	my(@output) = ();
+ 	$folder = Jcode->new($folder)->sjis;
  
  	dispText("Getting email message...\n");
  
***************
*** 850,855 ****
--- 854,860 ----
  	}
  
  	# Add some more special headers right before the message body.
+ 	my $folder = Jcode->new($folder)->jis;
  	my($gm_headers) = "X-gotmail-version: $gotmail_version\nX-gotmail-folder: $folder\nX-gotmail-user: $login\n";
  	s/^$/$gm_headers/m;
  
***************
*** 903,909 ****
  				if ($conf_save_to_login) {
  					$outfile .= $login;
  					if ($foldername ne "Inbox") {
! 						$outfile .= ("-" . $foldername);
  					}
  				} else {
  					$outfile .= $foldername;
--- 908,916 ----
  				if ($conf_save_to_login) {
  					$outfile .= $login;
  					if ($foldername ne "Inbox") {
! 					  if ($foldername ne "受信トレイ") {
! 					    $outfile .= ("-" . $foldername);
! 					  }
  					}
  				} else {
  					$outfile .= $foldername;
***************
*** 1008,1013 ****
--- 1015,1021 ----
  				if ( (!($name =~ /[<>]/)) && (!($name =~ /Trash Can/i)) &&
  				     (!($name =~ /Sent Messages/i)) && (!($name =~ /Drafts/i)) ) {
  					$" = "~";
+ 					$name = Jcode->new($name)->euc;
  					if (!@conf_folders || ("~@conf_folders~" =~ /~$name~/i)) {
  					  dispText ("Processing Folder: \"" . $name .
  						          "\", Total messages: " . $totalItems .

gotmail.diff

% ls gotmail.jp.patch            # パッチがあるか確認
gotmail.jp.patch
% tar xzf gotmail_0.7.9.tar.gz
% cd gotmail-0.7.9
% patch <../gotmail.diff

パッチをあてる

FTP サイトの更新

emacs-wiki.el のおかげでページの作成は非常に効率的になたが,ページが細切れに なった分,Web サーバーへの転送が面倒になってきた.そこで ftp ミラーリング用 の mirror (mirror-2.9) を使う.

% wget sunsite.uk.org/packages/mirror/mirror.tar.gz
--11:07:35--  http://sunsite.org.uk/packages/mirror/mirror.tar.gz
           => `mirror.tar.gz'
...
100%[====================================>] 123,194       64.16K/s    ETA 00:00

11:07:37 (64.16 KB/s) - `mirror.tar.gz' saved [123194/123194]
% mkdir mirror
% cd mirror
% tar xzf ../mirror.tar.gz
% cat >mirror.defaults
# default setting
site=ftp.geocities.co.jp
local_dir=/home/yourname/directory
remote_dir=/remote/directory
recursive=true
recurse_hard=true
do_deletes=true
max_delete_files=80%
max_delete_dirs=80%
dir_mode=0000
file_mode=0000
timeout=300

package=put
	get_file=false
package=get
	get_file=true
^D
% ln -s `pwd`/mirror.pl mirror

これで,後は

#!/bin/sh

NAME=yourname
MIRROR=mirror

case $1 in
        test)   $MIRROR -n -pput -u $NAME
                ;;
        put)    $MIRROR -pput -u $NAME
                ;;
        get)    $MIRROR -pget -u $NAME
                ;;
        *)      echo "[usage]" geoupdate "[put|get|test]"
                ;;
esac

ftpupdate

のようなシェルスクリプトを書いてパスを通しておけばコマンド一発で同期できる.

% ftpupdate put
Password for yourname:
package=put ftp.geocities.co.jp:/remote/directory -> /home/yourname/directory
Scanning local directory /home/yourname/directory
Scanning remote directory /remote/directory
compare directories (src 77, dest 77)
Put index.html 3522 bytes
Put WikiIndex.html 4398 bytes
Put EmacsWiki.html 28407 bytes
Put EmacsCustomize.html 233597 bytes
Put ChangeLog.html 2718 bytes
Put FreeBSDMemo.html 6585 bytes
Put EmacsLisp.html 5691 bytes
Put CLOS.html 8766 bytes
Put CLPDFjp.html 7243 bytes
Put LispDevelopEnvironment.html 9303 bytes
Put EmacsTips.html 2700 bytes
Put PythonClgrep.html 2847 bytes
Put LispLink.html 3892 bytes
Put PythonIntro.html 3905 bytes
Put RlwarpForGauche.html 2735 bytes
Put ScriptingWithLisp.html 6981 bytes
Put cmuclIntro.html 4347 bytes
Put cmuclMemo.html 6283 bytes

disconnecting from ftp.geocities.co.jp
All done, Exiting

実行画面

メッセージ ID の重複チェック

#!/usr/bin/env python

import os, re

def get_message_id(name):
    src = open(name)
    r = re.compile("^Message-ID: (.*)$")
    while 1:
        line = src.readline()
        m = r.match(line)
        if m: return m.group(1)

def main():
    files = os.listdir("./")
    files.reverse()
    news = {}
    for name in files:
        if name[0] != ".":
            id = get_message_id(name)
            if news.has_key(id) == 0: news[id] = name
            else:                     print name

if __name__ == '__main__':
    main()