summaryrefslogtreecommitdiffstats
path: root/konversation/scripts/mail
blob: 7757d4f0152f2b8425366f5a49d6b2cdbeea05b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash

#
# Licensed under GPL v2 or later at your option
# Copyright 2005 by John Tapsell <john.tapsell@kdemail.net>

PORT=$1;
SERVER=$2;
TARGET=$3;

FOLDER=$4;


if [ "$FOLDER" = "" ] ; then
  FOLDER="inbox"
fi


getmails()
{

  dcop kmail > /dev/null || {
    dcop $PORT default info "Sorry kmail is not running"
    exit
  }
  
  for f in $(dcop kmail KMailIface folderList) ; do
   MAILFOLDER=$(dcop $(dcop kmail KMailIface getFolder $f) "displayPath" | grep -i $FOLDER)
   if [ "$MAILFOLDER" != "" ] ; then
     FOUNDFOLDER=1
     MAILCOUNT=$(dcop $(dcop kmail KMailIface getFolder $f ) "unreadMessages()" )
     MAILTOTALCOUNT=$(dcop $(dcop kmail KMailIface getFolder $f ) "messages()" )
     MAILTOTALCOUNT=$(($MAILCOUNT + $MAILTOTALCOUNT))
     if [[ -z "$MAILCOUNT" ]] ; then MAILCOUNT = "0" ; fi
     if [ "$MAILCOUNT" != 0 ] ;  then
       FOUNDEMAIL=1
       echo "Email folder %B$MAILFOLDER%B has %B$MAILCOUNT%B unread messages, out of %B$MAILTOTALCOUNT%B"
     fi
   fi
  done

  if [[ -z "$FOUNDEMAIL" ]] ; then
    if [[ -z "$FOUNDFOLDER" ]] ; then
      dcop $PORT default info "No email folders were found that had a name containing '$FOLDER'"
      exit
    else
      echo "No new emails in any folders matching '$FOLDER'"
    fi
  fi

}

if [[ -z "$3" ]] ; then 
  echo "Scripts are not meant to be called from the command line."
  echo "This script should be installed to  $TDEDIR/share/apps/konversation/scripts"
  echo "Then executed with /script   from the konversation"
  echo
  echo The output is:
  getmails
  exit
fi

#LINECOUNT=$(getmails | wc -l)
#if [[ "$LINECOUNT" -gt 5 ]] ; then
#  dcop $PORT default info "There are more than 5 matches.  Cancelling to avoid flooding the server"
#  exit
#fi

getmails | head -n 3 | while read line; do dcop $PORT default say $SERVER "$TARGET" "$line"; done