1

I'm on Windows, using Irssi client irssi-win32-0.8.12.exe.

I'm having problems receiving a file with invalid name:

..nameo_\u2605_name.. (err: DCC can't create file)

How can I strip this invalid part "\u2605" from filename, using script?

This page doesn't help

I think this part of the Irssi source has something to do with it. Starting at line 195

/* if some plugin wants to change the file name/path here.. */
signal_emit("dcc get receive", 1, dcc);    
Borodin
  • 126,100
  • 9
  • 70
  • 144
xitrix
  • 11
  • 1
  • `\u2605` is Unicode U+2605, a Black Star - ★. You can't just remove characters in a Unicode file name as you would risk filename clashes. You need to support Unicode throughout your program. – Borodin Apr 04 '14 at 23:25
  • well i will resolve filename clashes somehow. True purpose is to be able change filename – xitrix Apr 05 '14 at 10:49
  • well i will resolve filename clashes somehow. True purpose is to be able change filename AT GET TIME, not after dowload. It does't matter - either have ascii only filename, or change all spaces to underscores. – xitrix Apr 05 '14 at 10:57

1 Answers1

0

I sure hope Irssi on Windows accepts scripts written in Perl. If this is the case, here's the solution:

use strict;
use warnings;

our $VERSION = "1.0";
our %IRSSI = ();

# interception made by registering signal as first + Irssi::signal_continue()
sub event_ctcp_dccsend {
    my ($server, $args, $nick, $addr, $target) = @_;

    # split incomming send request args into filename (either before first space or
    #  quoted), and the rest (IP, port, +optionally filesize)
    my ($filename, $rest) = $args =~ /((?:".*")|\S*)\s+(.*)/;

    # remember file name for informing sake
    my $oldname = $filename;
    # replace backslashes with "BSL" (change to anything you wish)
    if ($filename =~ s/\\/BSL/g) {
        # some info for user
        Irssi::print('DCC SEND request from '.$nick.': renamed bad filename '.$oldname.' to '.$filename);
        $args = $filename." ".$rest;
        # propagate signal; Irssi will proceed the request with altered arguments ($args) 
        Irssi::signal_continue($server, $args, $nick, $addr, $target);  
    }
}

# register signal of incoming ctcp 'DCC SEND', before anything else
Irssi::signal_add_first('ctcp msg dcc send', 'event_ctcp_dccsend');

The script intercepts "DCC SEND" ctcp messages and replaces all backslashes in the filename into "BSL" string, then forwards altered arguments of message to any other scripts and Irssi. If you want to remove all "\uXXXX" instead, use s/\\u\w{4}//g in place of s/\\/BSL/g

I hope it helps!

rud0lf
  • 186
  • 1
  • 8