[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sup-talk] best method for before-add-message.rb



Excerpts from Hamish D's message of Sun Feb 13 12:12:15 -0500 2011:
> > what would be the best way to match - for instance - the List-Id-Header in case
> > it's present? I've been wondering about this for a long time, right now, I'm
> > matching the raw-header against some regex, but it breaks if the line I'm
> > matching contains a newline (i.e. the header field is longer than one line).
> 
> Is there any reason you're not using the list_address member of
> message? It is derived from the List-Post header if present, or if
> not, the X-Mailing-List header. You can use it as, for example:
> 
> # Mark by email list
> if message.list_address.email =~ /sup-talk/
>   message.add_label "sup"
>   message.add_label "list"
> end
> 
> Hamish
I tried that and experienced varying success.
ie 2 or three 'add_label' is fine but adding and removing, for instance doesn't appear possible. I would assume most ppl here are interested in not only applying a label but also removing one in particular the inbox label.

Is anybody successfully both adding and removing a labels...in any way regexp, header...anything?

So far I've tried this:
addressfile = File.open("/home/plecavalier/.sup/hooks/label.lists","r")
if ! addressfile.grep(/#{message.list_address.email}/).empty?
  message.add_label :lists
end
addressfile = File.open("/home/plecavalier/.sup/hooks/label.lists","r")
if ! addressfile.grep(/#{message.list_address.email}/).empty?
  message.remove_label :inbox
end

In this case it appears handling a msg twice breaks everything. So then I tried this:

case message.list_address
  when /samba@lists.samba.org/
    message.add_label :lists
    message.add_label :samba
    message.remove_label :inbox
  when /cups@easysw.com/
    message.add_label :lists
    message.add_label :cups
    message.remove_label :inbox
end

This remains the closest I've come -thanks to Mark Alexander-. In this I was able to get multiple labels going for multiple msgs but again, very much hit-and-miss for label removal. I should probably not that message.remove_label in it's simplest form works fine. Just appears that it can't live alongside any other function.

I think we're starting to see that unless one is conversely adept in one form of language or another your odds of successfully adding labels upon receipt are in a manner which will create a robust searching db is quite low. Thus defeating in part the whole concept of this system. Don't mean to sound so negative here but I just to point out that from a none fluent regex/rudy....etc the wiki and mail archives leave you somewhat hanging.
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk