1use strict;
2use Text::Wrap;
3
4use vars qw($VERSION %IRSSI);
5$VERSION = '2007031900';
6%IRSSI = (
7	authors		=> 'Bitt Faulk',
8	contact		=> 'lxsfx3h02@sneakemail.com',
9	name		=> 'autowrap',
10	description	=> 'Automatically wraps long sent messages into multiple shorter sent messages',
11	license		=> 'BSD',
12	url		=> 'none',
13	modules		=> 'Text::Wrap',
14);
15
16sub event_send_text () {
17	my ($line, $server_rec, $wi_item_rec) = @_;
18	my @shortlines;
19	if (length($line) <= 400) {
20		return;
21	} else {
22		# split line, recreate multiple "send text" events
23		local($Text::Wrap::columns) = 400;
24		@shortlines = split(/\n/,wrap('','',$line));
25		foreach (@shortlines) {
26			if ($_ >= 400) {
27				Irssi::print("autowrap: unable to split long line.  sent as-is");
28				return;
29			}
30		}
31		foreach (@shortlines) {
32			Irssi::signal_emit('send text', $_,  $server_rec, $wi_item_rec);
33		}
34		Irssi::signal_stop();
35	}
36}
37
38Irssi::signal_add_first('send text', "event_send_text");
39