Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

formail and maildirs

  • 11-10-2004 4:48pm
    #1
    Banned (with Prison Access) Posts: 16,659 ✭✭✭✭


    I've just switched from mbox to maildirs, however I forgot about procmail. I
    use this to mark messages read in my archive folders, what's the equivalent
    for maildirs?
    | formail -I "Status: R" >> Lists/$MATCH
    
    adam


Comments

  • Closed Accounts Posts: 96 ✭✭krinDar


    Hi,
    dahamsta wrote:
    I forgot about procmail. I use this to mark messages read in my
    archive folders, what's the equivalent for maildirs?
    | formail -I "Status: R" >> Lists/$MATCH
    
    adam

    I assume you are doing something like:
    :0:
    * From: AMailList
    | formail -I "Status: R"  >> Lists/$MATCH
    

    And this no longer works because you have changed to Maildirs
    and you cannot cat into a directory.

    I believe this should do what you want.
    :0:
    * From: AMailList
    {
        :0 fw
         | formail -I "Status: R"
    
         :0:
          Lists/MailList/
    }
    

    What this does is first determine if the mail is from a maillist.
    If so it runs the nested commands. The first one, namely:
    :0 fw
    | formail -I "Status: R"
    

    calls formail, treating it as a filter (flag 'f') and waits for formail to return
    (flag 'w'). Formail changes the mail inline but does not redirect it to a
    file, it hands it back to procmail.

    The second piece just puts the mail into the Maildir for that list.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    That's very helpful krinDar and I'm nearly there but I still have one more problem: The formail rule was used to mark these messages read, however apparently Maildir flags the filename rather than the headers to mark message status. Any idea how I'd go about that? (I'm googling away, just thought you might know offhand.)

    Cheers,
    adam


  • Closed Accounts Posts: 96 ✭✭krinDar


    dahamsta wrote:
    That's very helpful krinDar and I'm nearly there but I still have one more problem: The formail rule was used to mark these messages read, however apparently Maildir flags the filename rather than the headers to mark message status. Any idea how I'd go about that? (I'm googling away, just thought you might know offhand.)

    Sorry, I think I started to see only the trees and not pay attention
    to the forest.

    In each Maildir there are three directories:cur, tmp, new.
    New, unread mail resides in the 'new' directory, mail that is in the process
    of being delivered stays in 'tmp' until it is completed. Old, read mail resides
    in the 'cur' directory.

    To mark a mail read in a Maildir, you move it from the new directory
    and append some information to the filename. This describes the
    format of the filenames:
    http://cr.yp.to/proto/maildir.html

    Thus, I guess a hack to do what you want would be something like:
    :0
    * From.*mailist*
    {
        :0
         lists/maildir
    
         :0
         | { cd lists/maildir; \
               for i in $(ls new)
               do
                   mv new/$i cur/${i}:2,S
                done
            }
    }
    

    All this does it move the files and appends the information to mark
    the file/mail read as necessary.

    This is a Kludge IMHO, and I have not tested it.

    You could also try to deliver to the Maildir _file_ as opposed to the
    Maildir itself. Typically we tell procmail to deliver to lists/maildir,
    and procmail handles to lower level problems, which
    directory it should put the mail into (lists/maildir/new) and the file
    it should put the mail into (as describe above).

    You could do this work yourself and save the mail to the
    lists/maildir/cur directory, e.g
    # replace with your hostname
    # this is the Maildir file to save to
    file=`perl -e 'printf("%s.%s_1.HOSTNAME:2,S",time,$$)
    
    :0:
    * From.*Mailist*
    lists/maildir/cur/$file
    

    I have tested this quickly and it appears to work a treat, it is
    however a bit of a kludge and could cause you problems depending
    on how you run procmail, if you get more than one mail for that
    list when you run procmail then we will try and put it into the
    same file, , though I do not believe this would be a
    problem, AFAICR procmail is called for each mail that is being
    delivered, so the file will be generated each time, with a new
    process number and possibly a new time, thus file should be
    unique.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    First one's a bit top-heavy since there'll be a substantial amount of mail in these directories, but the second solution is very trick, would seem to be exactly what I'm looking for. I'll set up a receipe with an extra backup and try it out, thanks.

    adam


  • Closed Accounts Posts: 96 ✭✭krinDar


    dahamsta wrote:
    First one's a bit top-heavy since there'll be a
    substantial amount of mail in these directories,

    Yeah it is a really rough approach that is bound to be affected by external
    things.
    but the second solution is very trick, would seem to be exactly
    what I'm looking for. I'll set up a receipe with an extra backup and try
    it out, thanks.

    Hopefully it will do what you want. What I could see going wrong with it, is that
    because you are delivering to an actual file, procmail will treat it as a mbox,
    thus it might manage to append multiple messages to the one file. You probably
    would not loose mail, just your maildir would be full of mboxes.

    The way this could occur is if procmail gets called with a batch of
    messages, as the variables would not change for that batch of
    messages. If you call procmail through your .forward file, this should
    not be a problem.

    A potential way to get around this is to increment the variable which
    counts the number of messages delivered in that batch. i.e in this
    file: 103342534.9435_C.moo.spoo.org:2,S, C is the counter. This
    is defined by the spec for Maildir so it is not that strange to do so.

    How to increment a variable within an action/rule, I am not sure.

    I guess another method that would be much more failsafe, but perhaps
    a little slower would be to write a utility to look in the maildir provided as
    an argument, create a unique filename, and put the mail in there.

    Do let us know how you get one with it.


  • Advertisement
  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    It's a little silly that procmail doesn't support this kind of thing by default, it's not exactly an unusual request. What bugs me is that when I asked my question on the Courier list it went ignored, and it's not the first time this happened either: my post included a reference to a previous unanswered question. I hate it when people's answer is to simply ignore the question, it's plain ignorant.

    Anyway, I'm nearly there now, I just have one more issue: I'm sorting this mail on the fly, from various Mailman mailing lists, however my test messages are failing for the simple reason that the directory for the list doesn't exist. This will happen in practise too as I subscribe to new lists, so I'm wondering what would be the best way of creating the directory on the fly?

    I know in the shell it would be something like if [ -e $DIR/ ], but I'm not sure how to integrate that into my procmail file. Here's my recipe so far:
    FILE=`perl -e 'printf("%s.%s_1.tedcrilly:2,S",time,$$)`
    
    :0
    * ^X-BeenThere: .+$
    {
       :0:
       .Lists/
    
       :0 fw
       | formail -I "Status: R"
    
       :0:
       * ^X-BeenThere: \/.+
       .Lists/$MATCH/cur/$FILE
    
    }
    
    adam


  • Closed Accounts Posts: 96 ✭✭krinDar


    dahamsta wrote:
    It's a little silly that procmail doesn't support this kind of thing by default, it's not exactly an unusual request.
    Creation of directories or writing directly to Maildir style files ?

    I am not sure, I mean, if you start adding loads of features like that
    I think it would become a little bloated. It is amazingly powerful to be
    able to call external "programs" however.
    I hate it when people's answer is to simply ignore the question, it's plain ignorant.

    *Ahem* - Sorry it took me so long to respond.

    so I'm wondering what would be the best way of creating the directory on the fly?

    I know in the shell it would be something like if [ -e $DIR/ ], but I'm not sure how to integrate that into my procmail file.

    In your nested rules you should be able to add the following:
    :0
    | if [ ! -e $DIR ]; \
       then mkdir -p $DIR; fi
    

    I think this is probably the best way of achieving what you want to do.


Advertisement