File: unread-mh.rc

package info (click to toggle)
procmail-lib 1:1995.08.28-4.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 156 kB
  • ctags: 32
  • sloc: perl: 213; makefile: 143
file content (90 lines) | stat: -rw-r--r-- 2,745 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# unread-mh.rc
#
# procmail recipe to compute how many unread messages
# for MH as the MUA (mail user agent).
#
# $Id: unread-mh.rc,v 1.3 1995/08/04 19:25:07 aks Exp $
#
#    Copyright (C) 1995  Alan K. Stebbens <aks@hub.ucsb.edu>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#
# Usage:
#
#   Referenced by "ackmail.rc" when MUA=mh and the text of the
#   reply includes the string '$UNREAD'
#
#   If MH_INFOLDERS is set, uses the output of "folder +$folder"
#   for each folder mentioned in MH_INFOLDERS.  The sum of the
#   current message number subtracted from the last message
#   number for each folder is returned.
#
#   If MH_INFOLDERS is not set, then check for the Unseen-Sequence
#   profile entry.  If this is set, uses the number of messages
#   in this sequence.
# 
#   If there is no Unseen-Sequence profile entry, or there is no
#   sequence in the +inbox, then use the output of 'folders +inbox'
#   as for MH_INFOLDERS above.
#

# Note: PATH should include the MH bin directory

UNREAD=no			# default output
SHELL=/bin/sh			# be sure

# If the user has defined one or more explicit folders in the
# variable MH_INFOLDERS, then use a shell script to get UNREAD
:0
* MH_INFOLDERS ?? .+
{
  UNREAD=`(for f in $MH_INFOLDERS ; do folder +$f ; done) |
	  sed -n -e 's/^.*- *\([0-9]*\)); cur= *\([0-9]*\);.*/ok \1 \2/p' |
	  awk '/ok/ { s+=$2-$3 } END { print s }'`
}

# If no explicit folder list, try using unseen sequences
:0 E
{
  # Get some MH info
  MH_INBOX=`mhpath +inbox`
  MH_UNSEENSEQ=`mhparam Unseen-Sequence`
  MH_INSEQFILE=$MH_INBOX/.mh_sequences

  :0 chW
  * MH_UNSEENSEQ ?? [a-z]+
  * ? test -f $MH_INSEQFILE
  * ? grep "^$MH_UNSEENSEQ:" $MH_INSEQFILE
  |UNREAD=`pick +inbox $MH_UNSEENSEQ 2>/dev/null | wc -l`

  # Ok -- no unseen sequence.  Try last resort of using +inbox info.
  :0 E
  {
    INFOLDER=`folder +inbox`
    :0
    * INFOLDER ?? cur= *\/[0-9]+
    { CUR=$MATCH
      :0
      * INFOLDER ?? messages *\( *[0-9]+- *\/[0-9]+
      { MAX=$MATCH
	:0
	* ? test "$MAX" -gt "$CUR"
	{ UNREAD=`expr $MAX - $CUR` }
      }
    }
  }
}