procmail
[Top] [All Lists]

Re: padding a string

2008-08-25 17:59:38
Hi Holger

Thank you very much for your help. Without it this would have taken me days to discover.

Mit freundlichen Grüßen

Nigel.


On 26/08/2008 8:44 AM, Holger Wahlen wrote:
* Nigel Allen wrote:
if length($string) < 6
 pad $string left spaces to 6;

You could add 6 spaces to the string unconditionally and then use the
last 6 characters of the result:

STRING="      $STRING"

:0
* STRING ?? ()\/......$
{
  STRING=$MATCH
}

:0
* ^X-My-Header:[ \t]*\/$
{
 STRING=${MATCH}
 :0
 * ? test ! -d $MATCH
 {
    ! bad_folder
 }
 $MATCH
}

Some more problems with that:

- "\t" doesn't work in procmail

- there's nothing for the \/ to capture

- you probably want "$STRING" instead of "$MATCH" once you've defined
  it (doesn't make a difference in that recipe, though)

- you need proper recipe syntax for the forwarding and the delivery

- the file should be locked for delivery

Try this (untested, though - set VERBOSE=on for debugging):

  :0  # brackets in the following line contain space and tab
  * ^X-My-Header:[  ]*\/.*
  {
    # pad with 6 spaces
    FILE="      $MATCH"

    :0
    * FILE ?? ()\/......$
    {
      FILE="$MATCH"
    }

    :0
    * ?! test -d "$FILE"
    ! bad_folder

    :0:
    "$FILE"
  }

/HW
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail
<Prev in Thread] Current Thread [Next in Thread>