procmail
[Top] [All Lists]

Re: assign a unique ID to each incoming email?

1999-04-06 08:01:32
I would like to use procmail to create some type of ticket number to 
incoming emails. That in itself is easy, but how do I keep track of the last
assigned number across mails, so that the numbers are nicely sequenced?

TIA
Mathias

I use the following. Note that some of the comments must be stripped
before it is used. The result of this is a variable, SERIAL, with a
unique number which can be used elsewhere. The variable FDT is the
'From ' date extracted from the message, TZ is the time zone I operate
under, REV is the revision number of my rc. The print statement can be
reduced to one line without the generated comments, but I prefer to
have the file self-documenting.

############################################### setup ............ serial number
## Assign a serial number to this mail. The number is kept in the external    ##
## file $PMRC/serial.rc. This section uses a global lock for serialization.   ##
##   NOTE: the rc file must exist and be seeded with a non-negative value.    ##
## This can be eliminated at the cost of a test -f for each message.          ##
################################################################################
  LOCKFILE=serial.rc$LOCKEXT  ## set global lock
  INCLUDERC=$PMRC/serial.rc   ## read current value
  :0                          ## increment
  * $ $SERIAL^0               ##  value just read
  *         1^0               ##  by 1
  { SERIAL=$=                 ##  save new value in variable
    :0 w i c                  ##  and update the
    | print -- "# Serial numbers assigned beginning v5.8 19971117\n\  ## history
      # Last message v$REV with header date: $FDT $TZ\n#\n\ ## date-time stamp
      SERIAL=$SERIAL" > $INCLUDERC      ##  and serial number in the rc file
  }                           ##
  LOCKFILE                    ##  clear global lock

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com