popfile-link.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. # * Copyright 2007 Tristan Chabredier <wwp@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. # popfile-link.sh helper script to open messages in POPFile's control center
  19. # in order to edit their status
  20. # Requires that POPFile is running and that the message has been processed
  21. # by it (X-POPFile-Link: header present). POPFile control center opens with
  22. # the web browser set in Claws Mail prefs.
  23. open_page()
  24. {
  25. TMPCMD=$(echo $OPEN_CMD | sed "s|\"%s\"|$1|")
  26. $TMPCMD &
  27. }
  28. SESSION_ID=""
  29. if [ "$1" = "--ask-session-id" ]
  30. then
  31. shift
  32. SESSION_ID=$(gxmessage -entry -center -wrap -buttons "OK:0,Cancel:1" -default "OK" \
  33. -name "popfile-link" -title "POPFile session ID" "Type in the ID of a running POPFile session to use")
  34. test -z "$SESSION_ID" -o $? -ne 0 && \
  35. exit 0
  36. fi
  37. test -z "$1" && \
  38. exit 1
  39. CM_DIR=$(claws-mail --config-dir)
  40. test -z "$CM_DIR" -o ! -d "$HOME/$CM_DIR" && \
  41. exit 1
  42. OPEN_CMD=$(grep -Em 1 "^uri_open_command=" "$HOME/$CM_DIR/clawsrc" | cut -d '=' -f 2-)
  43. test -z "$OPEN_CMD" && \
  44. exit 1
  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. if [ -n "$SESSION_ID" ]
  52. then
  53. open_page "${LINK}\\&session=$SESSION_ID"
  54. else
  55. open_page "$LINK"
  56. fi
  57. fi
  58. shift
  59. done
  60. exit 0