2007-11-26 [colin] 3.1.0cvs29
[claws.git] / tools / popfile-link.sh
1 #!/bin/sh
2
3 #  * Copyright 2007 Tristan Chabredier <wwp@claws-mail.org>
4 #  *
5 #  * This file is free software; you can redistribute it and/or modify it
6 #  * under the terms of the GNU General Public License as published by
7 #  * the Free Software Foundation; either version 3 of the License, or
8 #  * (at your option) any later version.
9 #  *
10 #  * This program is distributed in the hope that it will be useful, but
11 #  * WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  * General Public License for more details.
14 #  *
15 #  * You should have received a copy of the GNU General Public License
16 #  * along with this program; if not, write to the Free Software
17 #  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # popfile-link.sh               helper script to open messages in POPFile's control center
20 #                                               in order to edit their status
21
22 # Requires that POPFile is running and that the message has been processed
23 # by it (X-POPFile-Link: header present). POPFile control center opens with
24 # the web browser set in Claws Mail prefs.
25
26
27 function open_page()
28 {
29         TMPCMD=$(echo $OPEN_CMD | sed "s:%s:$1:")
30         $TMPCMD &
31 }
32
33
34 test -z "$1" && \
35         exit 1
36
37 CM_DIR=$(claws-mail --config-dir)
38 test -z "$CM_DIR" -o ! -d "$HOME/$CM_DIR" && \
39         exit 1
40
41 OPEN_CMD=$(grep -Em 1 "^uri_open_command=" "$HOME/$CM_DIR/clawsrc" | cut -d '=' -f 2-)
42 test -z "$OPEN_CMD" || \
43         exit 1
44
45 while [ -n "$1" ]
46 do
47         LINK=$(grep -Eim 1 "^X\-POPFile\-Link: " "$1")
48         if [ -n "$LINK" ]
49         then
50                 LINK=${LINK:16}
51                 open_page "$LINK"
52         fi
53         shift
54 done
55 exit 0