multiwebsearch.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. # * Copyright 2003-2007 Paul Mangan <paul@claws-mail.org>
  3. # *
  4. # * This file is free software; you can redistribute it and/or modify it
  5. # * under the terms of the GNU General Public License as published by
  6. # * the Free Software Foundation; either version 3 of the License, or
  7. # * (at your option) any later version.
  8. # *
  9. # * This program is distributed in the hope that it will be useful, but
  10. # * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # * General Public License for more details.
  13. # *
  14. # * You should have received a copy of the GNU General Public License
  15. # * along with this program; if not, write to the Free Software
  16. # * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. # *
  18. # Changes:
  19. # Feb 2007: add support for non ISO-8859-1 compatible locales
  20. # by Alex Gorbachenko <agent_007@immo.ru>
  21. #
  22. use Getopt::Long;
  23. use URI::Escape;
  24. use POSIX qw(locale_h);
  25. use Text::Iconv;
  26. my $where = '';
  27. my $what = '';
  28. GetOptions("where=s" => \$where,
  29. "what=s" => \$what);
  30. $locale = setlocale(LC_CTYPE);
  31. $locale =~ s/\S+\.//;
  32. $converter = Text::Iconv->new("$locale", "UTF-8");
  33. $safe=uri_escape($converter->convert("$what"));
  34. $what=$safe;
  35. chdir($ENV{HOME} . "/.claws-mail")
  36. || die("Can't find your ~/.claws-mail directory\n");
  37. open (CONF, "<multiwebsearch.conf")
  38. || die("Can't open ~/.claws-mail/multiwebsearch.conf\n");
  39. @conflines = <CONF>;
  40. close CONF;
  41. foreach $confline (@conflines) {
  42. if ($confline =~ m/^$where\|/) {
  43. chomp $confline;
  44. @parts = split(/\|/, $confline);
  45. $url = $parts[1];
  46. if ($parts[2]) {
  47. $what .= $parts[2];
  48. }
  49. }
  50. }
  51. if (!$url) {
  52. die("No url found with the alias \"$where\"\n");
  53. }
  54. open (SYLRC, "<clawsrc")
  55. || die("Can't open ~/.claws-mail/clawsrc\n");
  56. @rclines = <SYLRC>;
  57. close SYLRC;
  58. foreach $rcline (@rclines) {
  59. if ($rcline =~ m/^uri_open_command/) {
  60. chomp $rcline;
  61. @browser = split(/=/, $rcline);
  62. $browser[1] =~ s/%s/$url$what/;
  63. }
  64. }
  65. system("$browser[1]&");
  66. exit;