forked from PsychoticNinja/irssi
Update scripts to most recent version from scripts.irssi.org
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3931 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
74b4c07223
commit
fa6d77429a
106
scripts/buf.pl
106
scripts/buf.pl
@ -1,28 +1,28 @@
|
|||||||
# Highly experimental. use it at your own risk.
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use vars qw($VERSION %IRSSI);
|
use vars qw($VERSION %IRSSI);
|
||||||
|
|
||||||
use Irssi 20020120; # 21/01/2002, 18:00 cvs commit
|
use Irssi qw(command signal_add signal_add_first active_win
|
||||||
# at http://juerd.nl/irssi/temporary.deb for debian sid
|
settings_get_str settings_get_bool channels windows
|
||||||
$VERSION = "2.06";
|
settings_add_str settings_add_bool get_irssi_dir
|
||||||
|
window_find_refnum signal_stop);
|
||||||
|
$VERSION = '2.13';
|
||||||
%IRSSI = (
|
%IRSSI = (
|
||||||
authors => "Juerd",
|
authors => 'Juerd',
|
||||||
contact => "juerd\@juerd.nl",
|
contact => 'juerd@juerd.nl',
|
||||||
name => "Scroll buffer thingy",
|
name => 'Scroll buffer restorer',
|
||||||
description => "Saves the buffer for /upgrade",
|
description => 'Saves the buffer for /upgrade, so that no information is lost',
|
||||||
license => "Public Domain",
|
license => 'Public Domain',
|
||||||
url => "http://juerd.nl/irssi/",
|
url => 'http://juerd.nl/irssi/',
|
||||||
changed => "Tue Feb 28 16:22 CET 2002",
|
changed => 'Mon May 13 19:41 CET 2002',
|
||||||
changes => "+logging workaround (untested, suggested by darix)"
|
changes => 'Severe formatting bug removed * oops, I ' .
|
||||||
|
'exposed Irssi to ircII foolishness * sorry ' .
|
||||||
|
'** removed logging stuff (this is a fix)',
|
||||||
|
note1 => 'This script HAS TO BE in your scripts/autorun!',
|
||||||
|
note2 => 'Perl support must be static or in startup',
|
||||||
);
|
);
|
||||||
|
|
||||||
# Saves the Irssi scrollbuffer and displays it after /UPGADEing.
|
|
||||||
# Additionaly saves your settings and layout.
|
|
||||||
# HAS TO BE in $irssidir/scripts/autorun (don't forget to load the
|
|
||||||
# perl module if you have to... put /load perl in $irssidir/startup)
|
|
||||||
|
|
||||||
# Q: How can I get a very smooth and clean upgrade?
|
# Q: How can I get a very smooth and clean upgrade?
|
||||||
|
#
|
||||||
# A: /set -clear upgrade_separator
|
# A: /set -clear upgrade_separator
|
||||||
# /set upgrade_suppress_join ON (default)
|
# /set upgrade_suppress_join ON (default)
|
||||||
# /set channel_sync OFF
|
# /set channel_sync OFF
|
||||||
@ -31,6 +31,7 @@ $VERSION = "2.06";
|
|||||||
# Q: Is it possible to save my command history?
|
# Q: Is it possible to save my command history?
|
||||||
# Q: Can I prevent the screen from blinking?
|
# Q: Can I prevent the screen from blinking?
|
||||||
# Q: Can you make it faster?
|
# Q: Can you make it faster?
|
||||||
|
#
|
||||||
# A: Probably not, but if you can do it, tell me how.
|
# A: Probably not, but if you can do it, tell me how.
|
||||||
|
|
||||||
use Irssi::TextUI;
|
use Irssi::TextUI;
|
||||||
@ -39,94 +40,83 @@ use Data::Dumper;
|
|||||||
my %suppress;
|
my %suppress;
|
||||||
|
|
||||||
sub upgrade {
|
sub upgrade {
|
||||||
open (BUF, sprintf('>%s/scrollbuffer', Irssi::get_irssi_dir()));
|
open BUF, sprintf('>%s/scrollbuffer', get_irssi_dir) or die $!;
|
||||||
my $logging = Irssi::settings_get_bool('autolog') || 0;
|
print BUF join("\0", map $_->{server}->{address} . $_->{name}, channels), "\n";
|
||||||
print BUF join("\0", map $_->{server}->{address} . $_->{name}, Irssi::channels()), "\n";
|
for my $window (windows) {
|
||||||
print BUF "$logging\n";
|
|
||||||
for my $window (Irssi::windows()){
|
|
||||||
next unless defined $window;
|
next unless defined $window;
|
||||||
next if $window->{name} eq 'status';
|
next if $window->{name} eq 'status';
|
||||||
my $view = $window->view();
|
my $view = $window->view;
|
||||||
my $line = $view->get_lines();
|
my $line = $view->get_lines;
|
||||||
my $lines = 0;
|
my $lines = 0;
|
||||||
my $buf = '';
|
my $buf = '';
|
||||||
if (defined $line){
|
if (defined $line){
|
||||||
{
|
{
|
||||||
$buf .= $line->get_text(1) . "\n";
|
$buf .= $line->get_text(1) . "\n";
|
||||||
$line = $line->next();
|
$line = $line->next;
|
||||||
$lines++;
|
$lines++;
|
||||||
redo if defined $line;
|
redo if defined $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf BUF ("%s:%s\n%s", $window->{refnum}, $lines, $buf);
|
printf BUF "%s:%s\n%s", $window->{refnum}, $lines, $buf;
|
||||||
}
|
}
|
||||||
close BUF;
|
close BUF;
|
||||||
unlink sprintf("%s/sessionconfig", Irssi::get_irssi_dir());
|
unlink sprintf("%s/sessionconfig", get_irssi_dir);
|
||||||
Irssi::command('/layout save');
|
command 'layout save';
|
||||||
Irssi::command('/set autolog off') if $logging;
|
command 'save';
|
||||||
Irssi::command('/save');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub restore {
|
sub restore {
|
||||||
open (BUF, sprintf('<%s/scrollbuffer', Irssi::get_irssi_dir()));
|
open BUF, sprintf('<%s/scrollbuffer', get_irssi_dir) or die $!;
|
||||||
my @suppress = split /\0/, <BUF>;
|
my @suppress = split /\0/, <BUF>;
|
||||||
my $logging = <BUF>;
|
if (settings_get_bool 'upgrade_suppress_join') {
|
||||||
chomp $logging;
|
|
||||||
if (Irssi::settings_get_bool('upgrade_suppress_join')) {
|
|
||||||
chomp $suppress[-1];
|
chomp $suppress[-1];
|
||||||
@suppress{@suppress} = (2) x @suppress;
|
@suppress{@suppress} = (2) x @suppress;
|
||||||
}
|
}
|
||||||
Irssi::active_win()->command('/^window scroll off');
|
active_win->command('^window scroll off');
|
||||||
while (my $bla = <BUF>){
|
while (my $bla = <BUF>){
|
||||||
chomp $bla;
|
chomp $bla;
|
||||||
my ($refnum, $lines) = split /:/, $bla;
|
my ($refnum, $lines) = split /:/, $bla;
|
||||||
next unless $lines;
|
next unless $lines;
|
||||||
my $window = Irssi::window_find_refnum($refnum);
|
my $window = window_find_refnum $refnum;
|
||||||
unless (defined $window){
|
unless (defined $window){
|
||||||
<BUF> for 1..$lines;
|
<BUF> for 1..$lines;
|
||||||
Irssi::print("no $refnum?");
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
my $view = $window->view();
|
my $view = $window->view;
|
||||||
$view->remove_all_lines();
|
$view->remove_all_lines();
|
||||||
$view->redraw();
|
$view->redraw();
|
||||||
my $buf = '';
|
my $buf = '';
|
||||||
$buf .= <BUF> for 1..$lines;
|
$buf .= <BUF> for 1..$lines;
|
||||||
my $sep = Irssi::settings_get_str('upgrade_separator');
|
my $sep = settings_get_str 'upgrade_separator';
|
||||||
$sep .= "\n" if $sep ne '';
|
$sep .= "\n" if $sep ne '';
|
||||||
$window->gui_printtext_after(undef, MSGLEVEL_CLIENTNOTICE, "$buf\cO$sep");
|
$window->gui_printtext_after(undef, MSGLEVEL_CLIENTNOTICE, "$buf\cO$sep");
|
||||||
$view->redraw();
|
$view->redraw();
|
||||||
}
|
}
|
||||||
Irssi::active_win()->command('/^window scroll on');
|
active_win->command('^window scroll on');
|
||||||
Irssi::active_win()->command('/^scrollback end');
|
active_win->command('^scrollback end');
|
||||||
Irssi::command('/set autolog on') if $logging;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub suppress {
|
sub suppress {
|
||||||
my ($first, $second) = @_;
|
my ($first, $second) = @_;
|
||||||
return unless scalar keys %suppress
|
return
|
||||||
and Irssi::settings_get_bool('upgrade_suppress_join');
|
unless scalar keys %suppress
|
||||||
|
and settings_get_bool 'upgrade_suppress_join';
|
||||||
my $key = $first->{address} .
|
my $key = $first->{address} .
|
||||||
(grep { (s/^://, /^[#!+&]/) } split ' ', $second)[0];
|
(grep { (s/^://, /^[#!+&]/) } split ' ', $second)[0];
|
||||||
if (exists $suppress{$key} and $suppress{$key}--) {
|
if (exists $suppress{$key} and $suppress{$key}--) {
|
||||||
Irssi::signal_stop();
|
signal_stop();
|
||||||
delete $suppress{$key} unless $suppress{$key};
|
delete $suppress{$key} unless $suppress{$key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Don't use these :P they're for testing
|
settings_add_str 'buffer', 'upgrade_separator' => '=Upgrade=';
|
||||||
#Irssi::command_bind('emulate_upgrade', 'upgrade');
|
settings_add_bool 'buffer', 'upgrade_suppress_join' => 1;
|
||||||
#Irssi::command_bind('emulate_restore', 'restore');
|
|
||||||
|
|
||||||
Irssi::settings_add_str('buffer', 'upgrade_separator', '=Upgrade=');
|
signal_add_first 'session save' => 'upgrade';
|
||||||
Irssi::settings_add_bool('buffer', 'upgrade_suppress_join', 1);
|
signal_add_first 'session restore' => 'restore';
|
||||||
|
signal_add 'event 366' => 'suppress';
|
||||||
|
signal_add 'event join' => 'suppress';
|
||||||
|
|
||||||
Irssi::signal_add_first('session save', 'upgrade');
|
unless (-f sprintf('%s/scripts/autorun/buf.pl', get_irssi_dir)) {
|
||||||
Irssi::signal_add_first('session restore', 'restore');
|
|
||||||
Irssi::signal_add('event 366', 'suppress');
|
|
||||||
Irssi::signal_add('event join', 'suppress');
|
|
||||||
|
|
||||||
unless (-f sprintf('%s/scripts/autorun/buf.pl', Irssi::get_irssi_dir())) {
|
|
||||||
Irssi::print('PUT THIS SCRIPT IN ~/.irssi/scripts/autorun/ BEFORE /UPGRADING!!');
|
Irssi::print('PUT THIS SCRIPT IN ~/.irssi/scripts/autorun/ BEFORE /UPGRADING!!');
|
||||||
Irssi::print('And don\'t forget to /load perl using ~/.irssi/autostart');
|
|
||||||
}
|
}
|
||||||
|
343
scripts/mail.pl
343
scripts/mail.pl
@ -1,41 +1,106 @@
|
|||||||
# $Id: mail.pl,v 1.1 2002/03/10 21:33:46 cras Exp $
|
$VERSION = "2.92";
|
||||||
|
|
||||||
$VERSION = "2.0";
|
|
||||||
%IRSSI = (
|
%IRSSI = (
|
||||||
authors => "Matti Hiljanen, Timo Sirainen",
|
authors => "Timo Sirainen, Matti Hiljanen, Joost Vunderink, Bart Matthaei",
|
||||||
contact => "matti\@hiljanen.com, tss\@iki.fi",
|
contact => "tss\@iki.fi, matti\@hiljanen.com, joost\@carnique.nl, bart\@dreamflow.nl",
|
||||||
name => "mail",
|
name => "mail",
|
||||||
description => "Mail counter statusbar item with maildir support",
|
description => "Fully customizable mail counter statusbar item with multiple mailbox and multiple Maildir support",
|
||||||
license => "Public Domain",
|
license => "Public Domain",
|
||||||
url => "http://matin.maapallo.org/softa/irssi, http://irssi.org, http://scripts.irssi.de",
|
url => "http://irssi.org, http://scripts.irssi.de",
|
||||||
);
|
);
|
||||||
|
|
||||||
# Mail counter statusbar item
|
# Mail counter statusbar item
|
||||||
# for irssi 0.8.1 by Timo Sirainen
|
# for irssi 0.8.1 by Timo Sirainen
|
||||||
#
|
#
|
||||||
# Maildir support added by Matti Hiljanen
|
# Maildir support added by Matti Hiljanen
|
||||||
|
# Multiple Maildir/mbox and customization support added by Joost Vunderink
|
||||||
|
# OLD mailtreatment switch added by Bart Matthaei.
|
||||||
|
# Improved some regexps in maildirmode by Bart Matthaei.
|
||||||
|
# Maildirmode regexps (hopefully) fixed for good by Matti Hiljanen.
|
||||||
#
|
#
|
||||||
# /SET maildir_mode - ON/OFF
|
# You can add any number of mailboxes or Maildirs to watch for new mail in.
|
||||||
# /SET mail_file - specifies mbox file/Maildir location
|
# Give them any name and <name>:<count> will appear in your mail
|
||||||
# /SET mail_refresh_time - in seconds, how often to check for new mail
|
# statusbar item, where <count> is the number of unread messages.
|
||||||
# /SET mail_ext_program - specify external mail checker program
|
# If only 1 mailbox/Maildir is defined, the statusbar item will have the
|
||||||
|
# familiar form [Mail: <count>].
|
||||||
|
# If you set mail_show_message to ON, irssi will print a message in the
|
||||||
|
# active window whenever new mail arrives.
|
||||||
|
#
|
||||||
|
# Check /mailbox help for help.
|
||||||
|
|
||||||
use Irssi::TextUI;
|
use Irssi::TextUI;
|
||||||
|
|
||||||
my $maildirmode = 0; # maildir=1, file(spools)=0
|
my $maildirmode = 0; # maildir=1, file(spools)=0
|
||||||
|
my $old_is_not_new = 0;
|
||||||
my $extprog;
|
my $extprog;
|
||||||
my ($last_refresh_time, $refresh_tag);
|
my ($last_refresh_time, $refresh_tag);
|
||||||
|
|
||||||
# for mbox caching
|
# for mbox caching
|
||||||
my $last_size, $last_mtime, $last_mailcount, $last_mode;
|
my $last_size, $last_mtime, $last_mailcount, $last_mode;
|
||||||
|
|
||||||
|
# list of mailboxes
|
||||||
|
my %mailboxes = ();
|
||||||
|
my %new_mails_in_box = ();
|
||||||
|
my $nummailboxes = 0;
|
||||||
|
|
||||||
|
# the string to be stored in Irssi's mail_mailboxes setting
|
||||||
|
my $mailboxsetting = "";
|
||||||
|
|
||||||
|
sub cmd_print_help {
|
||||||
|
Irssi::print(
|
||||||
|
"MAILBOX ADD <num> <file|dir>\n".
|
||||||
|
"MAILBOX DEL <num>\n".
|
||||||
|
"MAILBOX SHOW\n\n".
|
||||||
|
"Statusbar item to keep track of how many (new) emails there are in ".
|
||||||
|
"each of your mailboxes/Maildirs.\n\n".
|
||||||
|
"/MAILBOX ADD <name> <file|dir>\n".
|
||||||
|
" - Adds a mailbox or a Maildir to the list.\n".
|
||||||
|
"/MAILBOX DEL <name>\n".
|
||||||
|
" - Removes mailbox or Maildir named <name> from the list.\n".
|
||||||
|
"/MAILBOX SHOW\n".
|
||||||
|
" - Shows a list of the defined mailboxes.\n\n".
|
||||||
|
"Use the following commands to change the behaviour:\n\n".
|
||||||
|
"/SET MAILDIRMODE on|off\n".
|
||||||
|
" - If maildirmode is on, the mailboxes in the list are assumed to be ".
|
||||||
|
"directories. Otherwise they are assumed to be spool files.\n".
|
||||||
|
" Default: off.\n".
|
||||||
|
"/SET MAIL_OLDNOTNEW on|off\n".
|
||||||
|
" - If switched on, mail marked als \"OLD\" will not be treated as new.\n".
|
||||||
|
" Default: off.\n".
|
||||||
|
"/SET MAIL_EXT_PROGRAM <prog>\n".
|
||||||
|
" - <prog> will be used to check for mail.\n".
|
||||||
|
"/SET MAIL_REFRESH_TIME <num>\n".
|
||||||
|
" - Sets the time between checks to <num> seconds.\n Default: 60.\n".
|
||||||
|
"/SET MAIL_SHOW_MESSAGE on|off\n".
|
||||||
|
" - If this is on, a message will be printed in the active window ".
|
||||||
|
"whenever new email is received.\n Default: off.\n".
|
||||||
|
"/SET MAIL_SHOW_ONLY_UNREAD on|off\n".
|
||||||
|
" - If you don't want to see a mailbox if it does not contain any new ".
|
||||||
|
"mail, set this to on.\n Default: on.\n" .
|
||||||
|
"/SET MAIL_SEPARATOR <char>\n".
|
||||||
|
" - Sets the character to be printed between each mailbox.\n".
|
||||||
|
" The default is a comma.\n".
|
||||||
|
"/SET MAIL_FORMAT <format>\n".
|
||||||
|
" - Sets the format of each mailbox.\n".
|
||||||
|
" Allowed variables:\n".
|
||||||
|
" %%n = mailbox name\n".
|
||||||
|
" %%u = number of unread mail\n".
|
||||||
|
" %%r = number of read mail\n".
|
||||||
|
" %%t = total amount of mail\n".
|
||||||
|
" The default format is %%n:%%u/%%t.\n".
|
||||||
|
"\nSee also: STATUSBAR"
|
||||||
|
,MSGLEVEL_CRAP);
|
||||||
|
}
|
||||||
|
|
||||||
sub mbox_count {
|
sub mbox_count {
|
||||||
my $mailfile = shift;
|
my $mailfile = shift;
|
||||||
my $count = 0;
|
my $unread = 0;
|
||||||
|
my $read = 0;
|
||||||
my $maildirmode=Irssi::settings_get_bool('maildir_mode');
|
my $maildirmode=Irssi::settings_get_bool('maildir_mode');
|
||||||
|
my $old_is_not_new=Irssi::settings_get_bool('mail_oldnotnew');
|
||||||
|
|
||||||
if ($extprog ne "") {
|
if ($extprog ne "") {
|
||||||
$count = `$extprog`;
|
$total = `$extprog`;
|
||||||
chomp $count;
|
chomp $unread;
|
||||||
} else {
|
} else {
|
||||||
if (!$maildirmode) {
|
if (!$maildirmode) {
|
||||||
if (-f $mailfile) {
|
if (-f $mailfile) {
|
||||||
@ -51,43 +116,139 @@ sub mbox_count {
|
|||||||
my $f = gensym;
|
my $f = gensym;
|
||||||
return 0 if (!open($f, $mailfile));
|
return 0 if (!open($f, $mailfile));
|
||||||
|
|
||||||
|
# count new mails only
|
||||||
|
my $internal_removed = 0;
|
||||||
while (<$f>) {
|
while (<$f>) {
|
||||||
$count++ if (/^From /);
|
$unread++ if (/^From /);
|
||||||
$count-- if (/^Subject: .*FOLDER INTERNAL DATA/);
|
|
||||||
|
if(!$old_is_not_new) {
|
||||||
|
$unread-- if (/^Status: R/);
|
||||||
|
} else {
|
||||||
|
$unread-- if (/^Status: [OR]/);
|
||||||
|
}
|
||||||
|
|
||||||
|
$read++ if (/^From /);
|
||||||
|
|
||||||
|
# Remove folder internal data, but only once
|
||||||
|
if (/^Subject: .*FOLDER INTERNAL DATA/) {
|
||||||
|
if ($internal_removed == 0) {
|
||||||
|
$internal_removed = 1;
|
||||||
|
$read--;
|
||||||
|
$unread--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close($f);
|
close($f);
|
||||||
$last_mailcount = $count;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
opendir(DIR, "$mailfile/cur") or return 0;
|
opendir(DIR, "$mailfile/cur") or return 0;
|
||||||
while (defined(my $file = readdir(DIR))) {
|
while (defined(my $file = readdir(DIR))) {
|
||||||
next if $file =~ /S/ || $file =~ /^(.|..)$/;
|
next if $file =~ /^(.|..)$/;
|
||||||
$count++;
|
# Maildir flags: http://cr.yp.to/proto/maildir.html
|
||||||
|
# My old regexps were useless if the MUA added any
|
||||||
|
# non-default flags -qvr
|
||||||
|
#
|
||||||
|
# deleted mail
|
||||||
|
next if $file =~ /\:.*?T.*?$/;
|
||||||
|
if($old_is_not_new) {
|
||||||
|
# when mail gets moved from new to cur it's name _always_
|
||||||
|
# changes from uniq to uniq:info, even when it's still not
|
||||||
|
# read. I assume "old mail" means mail which hasn't been read
|
||||||
|
# yet but it has been "acknowledged" by the user. (it's been
|
||||||
|
# moved to cur) -qvr
|
||||||
|
if ($file =~ /\:.*?$/) {
|
||||||
|
$read++;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($file =~ /\:.*?S.*?$/) {
|
||||||
|
$read++;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$unread++;
|
||||||
}
|
}
|
||||||
closedir(DIR);
|
closedir(DIR);
|
||||||
|
|
||||||
opendir(DIR, "$mailfile/new") or return 0;
|
opendir(DIR, "$mailfile/new") or return 0;
|
||||||
while (defined(my $file = readdir(DIR))) {
|
while (defined(my $file = readdir(DIR))) {
|
||||||
next if $file =~ /^(.|..)$/;
|
next if $file =~ /^(.|..)$/;
|
||||||
$count++;
|
$unread++;
|
||||||
}
|
}
|
||||||
closedir(DIR);
|
closedir(DIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $count;
|
|
||||||
|
if ($unread eq "" || $unread < 0) {
|
||||||
|
$unread = 0;
|
||||||
|
}
|
||||||
|
if ($read eq "" || $read < 0) {
|
||||||
|
$read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$last_mailcount = $unread;
|
||||||
|
|
||||||
|
return ($unread, $read);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks for mail and sets the statusbar item to the right string.
|
||||||
|
# Also shows a message in the active window if that setting is set.
|
||||||
sub mail {
|
sub mail {
|
||||||
my ($item, $get_size_only) = @_;
|
my ($item, $get_size_only) = @_;
|
||||||
|
|
||||||
$count = mbox_count(Irssi::settings_get_str('mail_file'));
|
my $result;
|
||||||
if ($count == 0) {
|
my $format = Irssi::settings_get_str('mail_format');
|
||||||
|
my $unread = 0;
|
||||||
|
my $read = 0;
|
||||||
|
my $total = 0;
|
||||||
|
|
||||||
|
# check all mailboxes for new email
|
||||||
|
foreach $name (keys(%mailboxes)) {
|
||||||
|
my $box = $mailboxes{$name};
|
||||||
|
# replace "~/" at the beginning by the user's home dir
|
||||||
|
$box =~ s/^~\//$ENV{'HOME'}\//;
|
||||||
|
|
||||||
|
($unread, $read) = mbox_count($box);
|
||||||
|
$unread = "0" if ($unread eq "");
|
||||||
|
$read = "0" if ($read eq "");
|
||||||
|
$total = $unread + $read;
|
||||||
|
$total = "0" if ($total eq "");
|
||||||
|
|
||||||
|
next if (Irssi::settings_get_bool('mail_show_only_unread') && $unread == 0);
|
||||||
|
|
||||||
|
if ($total eq "") { $total = 0; }
|
||||||
|
if (length($result) > 0) {
|
||||||
|
$result .= Irssi::settings_get_str('mail_separator');
|
||||||
|
}
|
||||||
|
my $string = $format;
|
||||||
|
$string =~ s/%n/$name/;
|
||||||
|
$string =~ s/%u/$unread/;
|
||||||
|
$string =~ s/%r/$read/;
|
||||||
|
$string =~ s/%t/$total/;
|
||||||
|
$result .= $string;
|
||||||
|
|
||||||
|
# Show -!- You have <num> new messages in <name>.
|
||||||
|
# Show this only if there are any new, unread messages.
|
||||||
|
if (Irssi::settings_get_bool('mail_show_message') &&
|
||||||
|
$unread > $new_mails_in_box{$name}) {
|
||||||
|
$new_mails = $unread - $new_mails_in_box{$name};
|
||||||
|
if ($nummailboxes == 1) {
|
||||||
|
Irssi::print("You have $new_mails new message" . ($new_mails != 1 ? "s." : "."), MSGLEVEL_CRAP);
|
||||||
|
} else {
|
||||||
|
Irssi::print("You have $new_mails new message" . ($new_mails != 1 ? "s " : " ") . "in $name.", MSGLEVEL_CRAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_mails_in_box{$name} = $unread;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length($result) == 0) {
|
||||||
# no mail - don't print the [Mail: ] at all
|
# no mail - don't print the [Mail: ] at all
|
||||||
if ($get_size_only) {
|
if ($get_size_only) {
|
||||||
$item->{min_size} = $item->{max_size} = 0;
|
$item->{min_size} = $item->{max_size} = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$item->default_handler($get_size_only, undef, $count, 1);
|
$item->default_handler($get_size_only, undef, $result, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +256,116 @@ sub refresh_mail {
|
|||||||
Irssi::statusbar_items_redraw('mail');
|
Irssi::statusbar_items_redraw('mail');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Adds the mailboxes from a string. Only to be used during startup.
|
||||||
|
sub add_mailboxes {
|
||||||
|
my $boxstring = $_[0];
|
||||||
|
my @boxes = split(/,/, $boxstring);
|
||||||
|
|
||||||
|
foreach $dbox(@boxes) {
|
||||||
|
my $name = $dbox;
|
||||||
|
$name = substr($dbox, 0, index($dbox, '='));
|
||||||
|
my $box = $dbox;
|
||||||
|
$box = substr($dbox, index($dbox, '=') + 1, length($dbox));
|
||||||
|
addmailbox($name, $box);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub addmailbox {
|
||||||
|
my ($name, $box) = @_;
|
||||||
|
|
||||||
|
if (exists($mailboxes{$name})) {
|
||||||
|
if ($box eq $mailboxes{$name}) {
|
||||||
|
Irssi::print("Mailbox $name already set to $box", MSGLEVEL_CRAP);
|
||||||
|
} else {
|
||||||
|
Irssi::print("Mailbox $name changed to $box", MSGLEVEL_CRAP);
|
||||||
|
$new_mails_in_box{$name} = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Irssi::print("Mailbox $name added: " . $box, MSGLEVEL_CRAP);
|
||||||
|
$new_mails_in_box{$name} = 0;
|
||||||
|
$nummailboxes++;
|
||||||
|
}
|
||||||
|
$mailboxes{$name} = $box;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub delmailbox {
|
||||||
|
my $name = $_[0];
|
||||||
|
|
||||||
|
if (exists($mailboxes{$name})) {
|
||||||
|
Irssi::print("Mailbox $name removed", MSGLEVEL_CRAP);
|
||||||
|
delete($mailboxes{$name});
|
||||||
|
delete($new_mails_in_box{$name});
|
||||||
|
$nummailboxes--;
|
||||||
|
} else {
|
||||||
|
Irssi::print("No such mailbox $name. Use /mailbox show to see a list.", MSGLEVEL_CRAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub update_settings_string {
|
||||||
|
my $setting;
|
||||||
|
|
||||||
|
foreach $name (keys(%mailboxes)) {
|
||||||
|
$setting .= $name . "=" . $mailboxes{$name} . ",";
|
||||||
|
}
|
||||||
|
|
||||||
|
Irssi::settings_set_str("mail_mailboxes", $setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cmd_addmailbox {
|
||||||
|
my ($name, $box) = split(/ +/, $_[0]);
|
||||||
|
|
||||||
|
if ($name eq "" || $box eq "") {
|
||||||
|
Irssi::print("Use /mailbox add <name> <mailbox> to add a mailbox.", MSGLEVEL_CRAP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addmailbox($name, $box);
|
||||||
|
update_settings_string();
|
||||||
|
refresh_mail();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cmd_delmailbox {
|
||||||
|
my $name = $_[0];
|
||||||
|
|
||||||
|
if ($name eq "") {
|
||||||
|
Irssi::print("Use /mailbox del <name> to delete a mailbox.", MSGLEVEL_CRAP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delmailbox($name);
|
||||||
|
update_settings_string();
|
||||||
|
refresh_mail();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cmd_showmailboxes {
|
||||||
|
if ($nummailboxes == 0) {
|
||||||
|
Irssi::print("No mailboxes defined.", MSGLEVEL_CRAP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Irssi::print("Mailboxes:", MSGLEVEL_CRAP);
|
||||||
|
foreach $box (keys(%mailboxes)) {
|
||||||
|
Irssi::print("$box: " . $mailboxes{$box}, MSGLEVEL_CRAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cmd_mailboxes {
|
||||||
|
my ($data, $server, $item) = @_;
|
||||||
|
if ($data =~ m/^[(show)|(add)|(del)]/i ) {
|
||||||
|
Irssi::command_runsub ('mailbox', $data, $server, $item);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Irssi::print("Use /mailbox (show|add|del).")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub init_mailboxes {
|
||||||
|
# Add the mailboxes at startup of the script
|
||||||
|
my $boxes = Irssi::settings_get_str('mail_mailboxes');
|
||||||
|
if (length($boxes) > 0) {
|
||||||
|
add_mailboxes($boxes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub read_settings {
|
sub read_settings {
|
||||||
$extprog = Irssi::settings_get_str('mail_ext_program');
|
$extprog = Irssi::settings_get_str('mail_ext_program');
|
||||||
my $time = Irssi::settings_get_int('mail_refresh_time');
|
my $time = Irssi::settings_get_int('mail_refresh_time');
|
||||||
@ -106,27 +377,37 @@ sub read_settings {
|
|||||||
}
|
}
|
||||||
return if ($mode == $last_mode);
|
return if ($mode == $last_mode);
|
||||||
$last_mode = $mode;
|
$last_mode = $mode;
|
||||||
if (!$mode) {
|
|
||||||
Irssi::settings_set_str('mail_file', "$ENV{'MAIL'}");
|
|
||||||
} else {
|
|
||||||
Irssi::settings_set_str('mail_file', "$ENV{'HOME'}/Maildir");
|
|
||||||
}
|
|
||||||
refresh_mail;
|
refresh_mail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!$maildirmode) {
|
if (!$maildirmode) {
|
||||||
Irssi::settings_add_str('misc', 'mail_file', $ENV{'MAIL'});
|
my $default = "1=" . $ENV{'MAIL'} . ",";
|
||||||
|
Irssi::settings_add_str('misc', 'mail_mailboxes', $default);
|
||||||
} else {
|
} else {
|
||||||
Irssi::settings_add_str('misc', 'mail_file', "$ENV{'HOME'}/Maildir");
|
my $default = "1=~/Maildir/,";
|
||||||
|
Irssi::settings_add_str('misc', 'mail_mailboxes', $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Irssi::command_bind('mailbox show', 'cmd_showmailboxes');
|
||||||
|
Irssi::command_bind('mailbox add', 'cmd_addmailbox');
|
||||||
|
Irssi::command_bind('mailbox del', 'cmd_delmailbox');
|
||||||
|
Irssi::command_bind('mailbox help', 'cmd_print_help');
|
||||||
|
Irssi::command_bind('mailbox', 'cmd_mailboxes');
|
||||||
|
|
||||||
Irssi::settings_add_str('misc', 'mail_ext_program', '');
|
Irssi::settings_add_str('misc', 'mail_ext_program', '');
|
||||||
Irssi::settings_add_int('misc', 'mail_refresh_time', 60);
|
Irssi::settings_add_int('misc', 'mail_refresh_time', 60);
|
||||||
Irssi::settings_add_bool('misc', 'maildir_mode', "$maildirmode");
|
Irssi::settings_add_bool('misc', 'maildir_mode', "$maildirmode");
|
||||||
|
Irssi::settings_add_bool('misc', 'mail_oldnotnew', "$old_is_not_new");
|
||||||
|
Irssi::settings_add_str('misc', 'mail_separator', ",");
|
||||||
|
Irssi::settings_add_bool('misc', 'mail_show_message', "0");
|
||||||
|
Irssi::settings_add_str('misc', 'mail_format', '%n:%u/%t');
|
||||||
|
Irssi::settings_add_bool('misc', 'mail_show_only_unread', "1");
|
||||||
|
|
||||||
Irssi::statusbar_item_register('mail', '{sb Mail: $0-}', 'mail');
|
Irssi::statusbar_item_register('mail', '{sb Mail: $0-}', 'mail');
|
||||||
|
|
||||||
read_settings();
|
read_settings();
|
||||||
|
init_mailboxes();
|
||||||
Irssi::signal_add('setup changed', 'read_settings');
|
Irssi::signal_add('setup changed', 'read_settings');
|
||||||
refresh_mail();
|
refresh_mail();
|
||||||
|
|
||||||
|
@ -1,52 +1,60 @@
|
|||||||
# /set splitlong_max_length
|
# /set splitlong_max_length
|
||||||
# specifies the maximum length of a msg, automatically chosen when set to "0"
|
# specifies the maximum length of a msg, automatically chosen when set to "0"
|
||||||
|
# default: 0
|
||||||
|
#
|
||||||
|
# /set splitlong_line_start
|
||||||
|
# /set splitlong_line_end
|
||||||
|
# self-explanatory
|
||||||
|
# defaults: "... ", " ..."
|
||||||
###
|
###
|
||||||
use strict;
|
use strict;
|
||||||
use vars qw($VERSION %IRSSI);
|
use vars qw($VERSION %IRSSI);
|
||||||
|
|
||||||
#don't know which version exactly, probably even works with 0.7.98.4
|
|
||||||
use Irssi 20011001;
|
use Irssi 20011001;
|
||||||
|
|
||||||
$VERSION = "0.17";
|
$VERSION = "0.20";
|
||||||
%IRSSI = (
|
%IRSSI = (
|
||||||
authors => "Bjoern \'fuchs\' Krombholz",
|
authors => "Bjoern \'fuchs\' Krombholz",
|
||||||
contact => "bjkro\@gmx.de",
|
contact => "bjkro\@gmx.de",
|
||||||
name => "splitlong",
|
name => "splitlong",
|
||||||
licence => "Public Domain",
|
licence => "Public Domain",
|
||||||
description => "Split overlong PRIVMSGs to msgs with length allowed by ircd",
|
description => "Split overlong PRIVMSGs to msgs with length allowed by ircd",
|
||||||
changed => "Wed Mar 8 03:03:10 CET 2002",
|
changed => "Wed Jun 25 00:17:00 CET 2003",
|
||||||
changes => "fixed some strange bug, depends on new switches to msg command (-nick|-channel)"
|
changes => "Actually the real 0.19 (now 0.20), but upload didn't work some month ago, target problem fixed..."
|
||||||
);
|
);
|
||||||
|
|
||||||
sub sig_command_msg {
|
sub sig_command_msg {
|
||||||
my ($cmd, $server, $winitem, $TEST) = @_;
|
my ($cmd, $server, $winitem) = @_;
|
||||||
my ($type, $target, $data) = $cmd =~ /^(\S*)\s(\S*)\s(.*)/;
|
my ( $param, $target,$data) = $cmd =~ /^(-\S*\s)?(\S*)\s(.*)/;
|
||||||
|
|
||||||
my $maxlength = Irssi::settings_get_int('splitlong_max_length');
|
my $maxlength = Irssi::settings_get_int('splitlong_max_length');
|
||||||
|
my $lstart = Irssi::settings_get_str('splitlong_line_start');
|
||||||
|
my $lend = Irssi::settings_get_str('splitlong_line_end');
|
||||||
|
|
||||||
if ($maxlength == 0) {
|
if ($maxlength == 0) {
|
||||||
# 497 = 510 - length(":" . "!" . " PRIVMSG " . " :");
|
# 497 = 510 - length(":" . "!" . " PRIVMSG " . " :");
|
||||||
$maxlength = 497 - length($server->{nick} . $server->{userhost} . $target);
|
$maxlength = 497 - length($server->{nick} . $server->{userhost} . $target);
|
||||||
}
|
}
|
||||||
my $maxlength2 = $maxlength - length("... ");
|
my $maxlength2 = $maxlength - length($lend);
|
||||||
|
|
||||||
if (length($data) > ($maxlength)) {
|
if (length($data) > ($maxlength)) {
|
||||||
my @spltarr;
|
my @spltarr;
|
||||||
|
|
||||||
while (length($data) > ($maxlength2)) {
|
while (length($data) > ($maxlength2)) {
|
||||||
my $pos = rindex($data, " ", $maxlength2);
|
my $pos = rindex($data, " ", $maxlength2);
|
||||||
push @spltarr, substr($data, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos) . " ...";
|
push @spltarr, substr($data, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos) . $lend;
|
||||||
|
$data = $lstart . substr($data, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
|
||||||
$data = "... " . substr($data, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
push @spltarr, $data;
|
push @spltarr, $data;
|
||||||
foreach (@spltarr) {
|
foreach (@spltarr) {
|
||||||
Irssi::signal_emit("command msg", "$type $target $_", $server, $winitem);
|
Irssi::signal_emit("command msg", "$target $_", $server, $winitem);
|
||||||
}
|
}
|
||||||
Irssi::signal_stop();
|
Irssi::signal_stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Irssi::settings_add_int('misc', 'splitlong_max_length', 0);
|
Irssi::settings_add_int('misc', 'splitlong_max_length', 0);
|
||||||
|
Irssi::settings_add_str('misc', 'splitlong_line_start', "... ");
|
||||||
|
Irssi::settings_add_str('misc', 'splitlong_line_end', " ...");
|
||||||
Irssi::command_bind('msg', 'sig_command_msg');
|
Irssi::command_bind('msg', 'sig_command_msg');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user