Fix operator for unmaintained translations conditions
[clawsker.git] / clawsker
index cda416d476ac899529e23533515a29220d9eb143..136a15625ed8d78195b96beb5e533a08fb3a5093 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -11,9 +11,7 @@
 # See COPYING file for license details.
 # See AUTHORS file for a complete list of contributors.
 #
-
-binmode STDOUT, ":encoding(utf8)";
-
+package Clawsker;
 use 5.010_000;
 use strict;
 use utf8;
@@ -26,7 +24,7 @@ use POSIX qw(setlocale);
 use Locale::gettext;
 use Encode;
 use Digest::MD5 qw(md5_hex);
-use Getopt::Long;
+use Getopt::Long qw(GetOptionsFromArray);
 
 my $NAME = 'clawsker';
 my $PREFIX = '@PREFIX@';
@@ -38,11 +36,14 @@ my $READONLY = FALSE;
 my $CLAWSV = undef;
 my $main_window = undef;
 
-my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
-$locale = "C" unless defined($locale);
-setlocale (LC_ALL, $locale);
-bindtextdomain ($NAME, catdir ($PREFIX, 'share', 'locale'));
-textdomain ($NAME);
+sub initialise {
+    binmode STDOUT, ":encoding(utf8)";
+    my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
+    $locale = "C" unless defined($locale);
+    setlocale (LC_ALL, $locale);
+    bindtextdomain ($NAME, catdir ($PREFIX, 'share', 'locale'));
+    textdomain ($NAME);
+}
 
 sub _ {
     my $str = shift;
@@ -212,6 +213,8 @@ sub _ {
     h_acc_gtls_set => _('Enables using user provided GnuTLS priority string.'),
     l_acc_gtls_pri => _('GnuTLS priority'),
     h_acc_gtls_pri => _('Value to use as GnuTLS priority string if custom priority check is enabled. Otherwise this value is ignored.'),
+    l_acc_tls_sni => _('Use TLS SNI extension'),
+    h_acc_tls_sni => _('Enables sending your hostname, if available, so the server can select the appropriate certificate for your domain. Useful for servers which host multiple domains on the same IP address.'),
 
     l_plu_gpg_alimit => _('Autocompletion limit'),
     h_plu_gpg_alimit => _('Limits the number of addresses obtained from keyring through autocompletion. Use 0 to get all matches.'),
@@ -289,23 +292,16 @@ sub version_greater_or_equal {
 }
 
 sub get_claws_version {
-    $_ = which ('claws-mail');
-    return "" unless defined $_; # not installed
-    my $res = "";
-    $_ = qx/$_ -v/;
-    chomp;
-    my @fver = split (/ /);
-    die "Invalid version string" unless ($fver[2] eq "version");
-    my @ver = split (/\./, $fver[3]);
-    $res .= "$ver[0].";
-    $res .= "$ver[1].";
-    if ($ver[2] =~ /(\d+)git(\d+)/) {
-        $res .= "$1.$2";
-    }
-    else {
-        $res .= "$ver[2].0";
-    }
-    return $res;
+    my $cm_path = which ('claws-mail') or return ""; # not found
+    open my $ph, "-|", $cm_path, "-v"  or return ""; # no pipe
+    chomp (my $v = <$ph>);
+    close $ph;
+    # Claws Mail version 3.17.2git17
+    $v =~ m/\bversion\s+(\d[\w.]+)/ or die "Invalid version string: '$v'";
+    my $cmv = $1;
+    my @ver = split m/(?:\.|git)/, $cmv;
+    @ver < 4 and push @ver, 0;
+    return join ".", @ver;
 }
 
 # data handlers and auxiliar functions
@@ -561,7 +557,7 @@ sub new_text_box_for_nchar($$$) {
     my $label = $$hash{$key}[LABEL];
     my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen,width
     my $glabel = Gtk3::Label->new ($label);
-    my $gentry = Gtk3::Entry->new ();
+    my $gentry = Gtk3::Entry->new;
     $gentry->set_max_length($type[2]) if defined ($type[2]);
     my $width = $type[3];
     $width //= $type[2];
@@ -1703,6 +1699,22 @@ sub new_colours_page() {
         '0.0.0',
         '-1',
     ],
+    sslman_w => [
+        'sslmanwin_width',
+        $xl::s{l_win_w},
+        $xl::s{h_win_w},
+        'int,0,3000', # 0 pixels - 3000 pixels
+        '0.0.0',
+        '486',
+    ],
+    sslman_h => [
+        'sslmanwin_height',
+        $xl::s{l_win_h},
+        $xl::s{h_win_h},
+        'int,0,3000', # 0 pixels - 3000 pixels
+        '0.0.0',
+        '-1',
+    ],
     plug_w => [
         'pluginswin_width',
         $xl::s{l_win_w},
@@ -1891,11 +1903,15 @@ sub new_winpos_subpage_prefs() {
 }
 
 sub new_winpos_subpage_misc() {
-    return new_grid_pack (3, 8, [
+    return new_grid_pack (4, 11, [
         [ _('Log window') ],
         [ new_text_box_for_int (\%pr::win, 'logw_w', \%HPVALUE),
             new_text_box_for_int (\%pr::win, 'logw_h', \%HPVALUE) ],
         [ '--' ],
+        [ _('SSL manager') ],
+        [ new_text_box_for_int (\%pr::win, 'sslman_w', \%HPVALUE),
+            new_text_box_for_int (\%pr::win, 'sslman_h', \%HPVALUE) ],
+        [ '--' ],
         [ _('Print preview window') ],
         [ new_text_box_for_int (\%pr::win, 'prin_w', \%HPVALUE),
             new_text_box_for_int (\%pr::win, 'prin_h', \%HPVALUE) ],
@@ -1939,14 +1955,24 @@ sub new_winpos_page() {
         '3.9.0.181',
         '0',
     ],
+    tls_sni => [
+        'use_tls_sni',
+        $xl::s{l_acc_tls_sni},
+        $xl::s{h_acc_tls_sni},
+        'bool',
+        '3.17.2.16',
+        '0',
+    ],
 );
 
 sub new_account_subpage($) {
     my ($akey) = @_;
-    return new_grid_pack (1, 3, [
+    return new_grid_pack (1, 5, [
         [ _('GnuTLS priority') ],
         [ new_check_button_for (\%pr::acc, 'tls_set', $ACHPVALUE{$akey}) ],
-        [ new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey}) ]
+        [ new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey}) ],
+        [ _('Server Name Indication') ],
+        [ new_check_button_for (\%pr::acc, 'tls_sni', $ACHPVALUE{$akey}) ],
     ]);
 }
 
@@ -2074,19 +2100,19 @@ sub new_plugins_page() {
 }
 
 sub new_hotkeys_list_label {
-    my $renderer = Gtk3::CellRendererText->new ();
+    my $renderer = Gtk3::CellRendererText->new;
     $renderer->set_property('alignment' => 'left');
     $renderer->set_property('editable' => FALSE);
     return $renderer;
 }
 
 sub new_hotkeys_list_hotkey {
-    my $renderer = Gtk3::CellRendererAccel->new ();
+    my $renderer = Gtk3::CellRendererAccel->new;
     $renderer->set_property ('accel-mode' => 'gtk');
     $renderer->set_property ('editable' => TRUE);
     $renderer->signal_connect ('accel-edited' => sub {
         my ($w, $path, $key, $mods, $keycode) = @_;
-        my $accel = Gtk3::Accelerator->name ($key, $mods);
+        my $accel = Gtk3::accelerator_name ($key, $mods);
         my ($model, $iter) = $SELHOTKEY->get_selected ();
         $model->set($iter, C_HOTKEY, "\"$accel\"");
         my $gkey = $model->get_value ($iter, C_GROUP);
@@ -2168,23 +2194,21 @@ sub new_hotkeys_list {
 }
 
 sub new_hotkeys_page() {
-    my $swin = Gtk3::ScrolledWindow->new ();
-    my $vbox = Gtk3::VBox->new (FALSE, 5);
+    my $hkbook = Gtk3::Notebook->new;
+    $hkbook->set_tab_pos ('right');
     foreach my $gkey (sort keys %$HOTKEYS) {
         my $group = $HOTKEYS->{$gkey};
-        # group title
-        my $glabel = new_title ($gkey);
-        $glabel->set_padding (5, 1);
-        $vbox->pack_start ($glabel, FALSE, FALSE, 0);
-        # group key list
         my $keylist = new_hotkeys_list ($gkey, $group);
-        $vbox->pack_start ($keylist, FALSE, FALSE, 0);
+        # prepare scrolled window
+        my $swin = Gtk3::ScrolledWindow->new;
+        $swin->set_border_width (5);
+        $swin->set_shadow_type ('none');
+        $swin->set_policy ('automatic', 'automatic');
+        # add list of keys
+        $swin->add ($keylist);
+        $hkbook->append_page ($swin, new_label ($gkey));
     }
-    $swin->set_border_width (5);
-    $swin->set_shadow_type ('none');
-    $swin->set_policy ('automatic', 'always');
-    $swin->add_with_viewport ($vbox);
-    return $swin;
+    return $hkbook;
 }
 
 sub new_info_page() {
@@ -2228,31 +2252,29 @@ sub get_toolkit_versions {
 }
 
 sub print_version() {
-    print $xl::s{about_title} . "\n";
-    print $xl::s{about_version} . " $VERSION\n";
+    say $xl::s{about_title};
+    say _('Version:') . " $VERSION";
     my $v = get_toolkit_versions ();
     if ($v->{'glib-b'}) {
-        print _("Perl-GLib version {glibv}, built for {glibb}, running with {glibr}.",
+        say _("Perl-GLib version {glibv}, built for {glibb}, running with {glibr}.",
                 glibv => $v->{'glib'},
                 glibb => $v->{'glib-b'},
                 glibr => $v->{'glib-r'});
     } else {
-        print _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
+        say _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
     }
-    print "\n";
     if ($v->{'gtk-b'}) {
-        print _("Perl-GTK3 version {gtkv}, built for {gtkb}, running with {gtkr}.",
+        say _("Perl-GTK3 version {gtkv}, built for {gtkb}, running with {gtkr}.",
                 gtkv => $v->{'gtk'},
                 gtkb => $v->{'gtk-b'},
                 gtkr => $v->{'gtk-r'});
     } else {
-        print _("Perl-GTK3 version {gtkv}.", gtkv => $v->{'gtk'});
+        say _("Perl-GTK3 version {gtkv}.", gtkv => $v->{'gtk'});
     }
-    print "\n";
     my $clawsver = ($CLAWSV eq "") ?
                 _("Claws Mail was not found!") :
                 _("Claws Mail returned version {cmv}.", cmv => $CLAWSV);
-    print $clawsver . "\n";
+    say $clawsver;
 }
 
 # the command line help
@@ -2276,10 +2298,12 @@ sub print_help() {
 }
 
 sub parse_command_line {
+    my $argv = shift;
     my $cont = TRUE;
     $CLAWSV = get_claws_version ();
     eval {
-        GetOptions('h|help' => sub { print_help (); $cont = FALSE },
+        GetOptionsFromArray($argv,
+            'h|help' => sub { print_help (); $cont = FALSE },
             'v|version' => sub { print_version (); $cont = FALSE },
             'b|verbose' => sub { $VERBOSE = TRUE },
             'r|read-only' => sub { $READONLY = TRUE },
@@ -2526,7 +2550,6 @@ sub save_rc_preferences {
     my $rc = get_rc_filename ();
     log_message ("Saving preferences to $rc\n");
     return FALSE unless check_rc_file ($rc);
-    return FALSE unless check_claws_not_running ();
     return FALSE unless backup_resource ($rc);
     foreach (keys %PREFS) {
         if (defined $HPVALUE{$_}) {
@@ -2548,7 +2571,6 @@ sub save_ac_preferences {
     my $rc = get_ac_rc_filename ();
     log_message ("Saving account preferences to $rc\n");
     return FALSE unless check_rc_file ($rc);
-    return FALSE unless check_claws_not_running ();
     return FALSE unless backup_resource ($rc);
     foreach my $asect (keys %$ACCOUNTDATA) {
         if ($asect =~ /^Account: (\d+)$/) {
@@ -2567,13 +2589,13 @@ sub save_hk_preferences {
     my $rc = get_menurc_filename ();
     log_message ("Saving hotkey preferences to $rc\n");
     return FALSE unless check_rc_file ($rc);
-    return FALSE unless check_claws_not_running ();
     return FALSE unless backup_resource ($rc);
     save_menurc ($rc, $HOTKEYS);
     return TRUE;
 }
 
 sub save_preferences {
+    return FALSE unless check_claws_not_running ();
     my $result = save_rc_preferences ()
         and save_ac_preferences ()
         and save_hk_preferences ();
@@ -2720,24 +2742,29 @@ sub escape_key_handler {
     }
 }
 
-# initialise
-exit unless parse_command_line ();
-Gtk3->init;
-$main_window = Gtk3::Window->new ('toplevel');
-exit unless load_preferences ();
-exit unless init_hidden_preferences ();
-# create main GUI
-my $box = Gtk3::VBox->new (FALSE, 5);
-$box->set_border_width(3);
-my $about = new_about_dialog ($main_window);
-$box->pack_start (new_notebook (), TRUE, TRUE, 0);
-$box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
-$main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
-$main_window->signal_connect (key_press_event => \&escape_key_handler);
-$main_window->set_title (_('Claws Mail Hidden Preferences'));
-$main_window->set_icon_list (get_app_icons ());
-$main_window->add ($box);
-$main_window->show_all;
-$MODIFIED = 0;
-Gtk3->main;
-
+sub main {
+    my $args = shift;
+    initialise;
+    exit unless parse_command_line ($args);
+    Gtk3->init;
+    $main_window = Gtk3::Window->new ('toplevel');
+    exit unless load_preferences ();
+    exit unless init_hidden_preferences ();
+    # create main GUI
+    my $box = Gtk3::VBox->new (FALSE, 5);
+    $box->set_border_width(3);
+    my $about = new_about_dialog ($main_window);
+    $box->pack_start (new_notebook (), TRUE, TRUE, 0);
+    $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
+    $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
+    $main_window->signal_connect (key_press_event => \&escape_key_handler);
+    $main_window->set_title (_('Claws Mail Hidden Preferences'));
+    $main_window->set_icon_list (get_app_icons ());
+    $main_window->add ($box);
+    $main_window->show_all;
+    $MODIFIED = 0;
+    Gtk3->main;
+    return 0;
+}
+
+exit Clawsker::main(\@ARGV) unless caller;