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

From: Philippe LeCavalier <[email-masked]>
Date: Thu, 10 Feb 2011 14:19:49 -0500

Hi. I apologize in advance for the broken thread...Since I forgot a  linebreak at the beginning of the body so everything got mangled upon exiting vim. I did my best to re-create the order.

Excerpts from Mark Alexander's message of Thu Feb 10 12:00:17 -0500 2011: 

> Excerpts from Philippe LeCavalier's message of Thu Feb 10 11:52:53 -0500 2011:

> > Hi Mark. 
> > Have you tried? 
> > > >  case message.subj 
> >  when /\[P4 SUBMIT/ 
> >    message.add_label :p4 
> >   message.remove_label :inbox 
> > end 
> > No, I haven't tried remove_label.

I did some testing and for some reason I cannot see, the above code automatically archives the msg without any obvious code telling sup to do so.

If I:

  case message.from.email
  when /@plecavalier.com/
    message.add_label :TEST
    message.add_label :TEST2
    message.add_label :TEST3
  end

tests sent to myself are respectively labeled TEST TEST2 TEST3 but are also striped of the inbox label. Since this is exactly what I want this works for me but...
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Philippe LeCavalier <[email-masked]>
Date: Thu, 10 Feb 2011 17:09:11 -0500

Hi All.
> tests sent to myself are respectively labeled TEST TEST2 TEST3 but are also striped of the inbox label. Since this is exactly what I want this works for me but...

Well, I don't know if this was the most efficient method but I took Mark's example and ran with it. This method accomplishes my goal to add(and remove!) multiple labels in one swish and is legible enough for the simple-minded like myself.

Note: the above statement re. removing the inbox label without having specifying it explicitely is false...No idea why Sup was doing that but restarting sup completely, fixed that oddity. Perhaps my understanding of 'H' is incorrect!?

Thanks a bunch Mark my inbox is well on it's way to 0 as it once was.
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Hamish D <[email-masked]>
Date: Sun, 13 Feb 2011 17:12:15 +0000

> 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

---

From: Philippe LeCavalier <[email-masked]>
Date: Thu, 10 Feb 2011 09:44:18 -0500

Hi All.

I'm still working on my initial labeling/hooks and best choices thereof.

I'm torn between a few options.

i)external file reference (would be my preferred method)
-can't list anything other than full email addresses in the file
@domain.com, wildcards...etc. would be nice
-can't comment in the file. It would be nice to weed out comments
-is it possible that when an address has a subdomain the example in the wiki breaks? ie [email-masked]
none of my hooks for these types of addresses seem to work
-is Sup caching the referenced file? if not, I presume this option significantly slows things down

ii)not using an external file makes the hook file lengthy. However it seems to be the only safe way of adding multiple labels - which I feel crucial to making a strong searchable system. Perhaps a label(s)-markread-archive would be nice :)
-using this method I find myself writing a ton of rules for the same thread.
a)label the thread from a particular community/client/area
b)label the thread from a particular person within said community/clientel/area
c)label it something useful ie (not)important/archive/redirect/bounce(hehe)...etc.

I'm assuming my difficulties spring from a few basic assumptions;
I can't write any code let alone Ruby, if my life depended on it.
The wiki has solid working examples for those who can work with Ruby. Again I don't speak Ruby.
And mostly, I come form a world where things get filtered to folders :-( I'm really trying to keep an open mind and I know I'll get there but my inbox now has thousands of mails in it and I'm the type that kept a strict 0 count. In order for me to move to Sup I had to get *real* disorganized before getting *real* organized ;-) All that to say that for types like me, it's all about copying other, less ruby-challenged, peoples work. So for the past three weeks I've been living in the wiki....It's a pretty lonely place out there!

In keeping an open mind about all this, I'm open to hearing examples of how others handle there workflow that are achieving the same goal I have in mind. ie label everything with individual labels and archive it all using the least/simplest/most efficient code possible. This way I can search for clients,client A,reports,after:tue-jan-18(I think the latter is prob. wrong but feel like looking up chronic's standards at the moment:-) )

My mail is really important to me so if the only response I get from this is "learn Ruby you lazy-ass-bastard!" I'll get the message(lousy pun eh?) ;-)
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Moritz Wilhelmy <[email-masked]>
Date: Sun, 13 Feb 2011 02:34:27 +0100

Hi,

Is there any way around this? Right now I'm doing something along the lines of
this:

# Mailing lists
lids_re = {
  /<foo\.lists\.foo\.com>/           => "foo",
  /<dev\.something\.org>/            => ["something", "devel"]
}

def add_labels message, labels
    labels.each do |l|
        message.add_label l
    end
end

if message.raw_header =~ /^List-I[dD]: ([^\n]+)/
    #log "List ID: #{$1}"
    message.add_label "list"
    lids_re.keys.each do |re|
        add_labels message lids_re[re] if $1 =~ re
    end
end

Can I pull arbitrary, parsed headers directly out of the message object, or do
I have to do my own parsing?

Best regards,

Moritz

---

From: Rich Lane <[email-masked]>
Date: Sun, 13 Feb 2011 12:45:04 -0500

Excerpts from Tero Tilus's message of 2011-02-13 04:51:02 -0500:
> Moritz Wilhelmy, 2011-02-13 03:34:
> > Can I pull arbitrary, parsed headers directly out of the message
> > object, or do I have to do my own parsing?
> 
> Uh, oh.  Looks like no, but it is pretty close, berause
> Message#parse_header already builds parsed hash of arbitrary headers
> internally.
> 

I use "hs = message.source.load_header(message.source_info)", which we
should probably make a convenience method on Message.
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Moritz Wilhelmy <[email-masked]>
Date: Sun, 13 Feb 2011 14:00:27 +0100

Hello,

Excerpts from Tero Tilus's message of Sun Feb 13 10:51:02 +0100 2011:
> > what would be the best way to match - for instance - the
> > List-Id-Header in case it's present?
> List-Id is a whole separate kind of beast.  My stragy dealing with it
> looks like this.  Comments in finnish.  Go google translate. ;)
Ah, well, the problem I have is something like this

List-Id: "very long descriptive text on what the list is about"
    <list.lists.something.com>

Because the actual List-Id is so long, it's sometimes wrapped into the next
line per convention (i.e. when the descriptive text is already very long and
the line needs to be wrapped because the actual List-Id would exceed the
character limit per line, I think it's around 80 characters). Thus, my regexes
don't match in all cases. I want to match the list by the part between the <>,
not the descriptive text, which is a bit problematic because of the
line-wrapping. However, if I could get the full List-Id line from the parsed
headers hashtable, this would eliminate my parsing problems.

> Message#parse_header already builds parsed hash of arbitrary headers

Well, making this publicly accessible to the before-add-message hook would
simplify a lot of the stuff I do with my email in order to place the right
labels. So maybe, this is a feature request to the sup developers, but maybe I
also got everything wrong. ;)

Cheers,

Moritz

---

From: Tero Tilus <[email-masked]>
Date: Sun, 13 Feb 2011 11:51:02 +0200

== clip from ~/.sup/hooks/before-add-message.rb ==
hdr = message.raw_header

# Yritetään hakea listalle label List-Id headerista ja jos sellaista
# ei ole (mm. pipermail-arkistot) niin otsikkoriviltä [listanimestä].
# Listaheadereita on montaa sorttia
#
# List-Id: effi-alert.winston.effi.org
# List-Id: <effipalvelin.winston.effi.org>
# List-Id: EFFIn hallituksen keskusteluja <board.effi.org>
# List-Id: =?iso-8859-1?q?Keski-Suomen_EFFIl=E4iset?= <ks-effi.lists.jyu.fi>
# List-Id: "Hear ry:n julkinen tiedotuslista: Radio Hear, Linnunlaulupubi,
# List-Id: =?iso-8859-1?q?El=E4m=E4_on_peli=E4=2C_j=E4rjest=E4j=E4lista?=

if m = (hdr.match(/^List-Id: +[^<]*<([^>\s]+)> *$/i) or # tyyppi 1
        hdr.match(/^List-Id: +([^<>=\s]+) *$/i) or      # tyypit 2-4
        hdr.match(/^Subject: +\[ *([^\] ]+) *\]/i))
  list_id = m[1]
  list_id = 'effi-hallitus' if list_id == 'board.effi.org'
  list_id = 'effi-asiantuntijat' if list_id == 'asiantuntijat.effi.org'
  list_id = 'maahinkainen-jasenet' if list_id == 'jasenet.maahinkainen.org'
  list_id = 'lev' if list_id == 'lev-list'
  list_id = list_id.split('.', 2)[0].downcase
  message.add_label list_id
end

== clip end ==

--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Mark Alexander <[email-masked]>
Date: Thu, 10 Feb 2011 11:40:38 -0500

> @domain.com, wildcards...etc. would be nice

I'm not sure if this will help (it's pretty primitive), but here's
my before-add-message.rb, showing how to do regular expression
matches on addresses:

# Label by subject.  This is useful for messages
# generated automatically by Bugzilla or cron jobs.
case message.subj
when /\[P4 SUBMIT/
  message.add_label :p4
when /\[Bug.*project:/
  message.add_label :projbugs
when /\[Bug/
  message.add_label :bugs
when /project.*suite results/
  message.add_label :testing
end

# Label by recipients.  This is useful for mailing lists.
to_string = message.recipients.map { |t| t.email }.join(" ")
case to_string
# Personal labels
when /\bsup-(devel|talk)@rubyforge.org\b/
  message.add_label :sup
# Work labels
when /pi@widgets/
  message.add_label :pi
when /git-users@widgets/
  message.add_label :git
when /team-project@widgets/
  message.add_label :project
end

# Label by from.  This is useful for personal emails.
case message.from.email
when /@amazon/
  message.add_label :amazon
when /@facebook/
  message.add_label :facebook
when /@netflix/
  message.add_label :netflix
when /[email-masked][email-masked]/
  message.add_label :somebody
end
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Philippe LeCavalier <[email-masked]>
Date: Sun, 13 Feb 2011 13:08:23 -0500

> if message.list_address.email =~ /sup-talk/
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 /[email-masked]/
    message.add_label :lists
    message.add_label :samba
    message.remove_label :inbox
  when /[email-masked]/
    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
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk