[#52047] ruby-talk separation, part II — " JamesBritt" <james@...>

32 messages 2002/10/01
[#52099] Re: ruby-talk separation, part II — Holden Glova <dsafari@...> 2002/10/01

-----BEGIN PGP SIGNED MESSAGE-----

[#52111] Re: ruby-talk separation, part II — "Bulat Ziganshin" <bulatz@...> 2002/10/01

[#52118] Re: ruby-talk separation, part II — Jim Freeze <jim@...> 2002/10/01

On Tue, Oct 01, 2002 at 09:03:44PM +0900, Bulat Ziganshin wrote:

[#52167] Re: ruby-talk separation, part II — Sean Chittenden <sean@...> 2002/10/01

FreeBSD's got a decent setup. Few additions to the list here:

[#52245] Compiling stuff under Windows: list of problems — "Gavin Sinclair" <gsinclair@...>

I don't want my tortuous experience of trying to get things working under this

13 messages 2002/10/02

[#52259] bugs — "Kontra, Gergely" <kgergely@...>

Hi!

26 messages 2002/10/02
[#52261] Re: bugs — nobu.nokada@... 2002/10/02

Hi,

[#52269] Re: bugs — "Stathy G. Touloumis" <stathy.touloumis@...> 2002/10/02

[#52300] Can soneone tell me what I'm doing wrong... — Jeremy Gregorio <gunvalk@...>

I'm trying to write a little script to rename my mp3s I started with this:

15 messages 2002/10/02

[#52391] CRuby (Was: R) — Nikodemus Siivola <tsiivola@...>

CRuby = subset of Ruby + typed methods + compiler to C

28 messages 2002/10/03
[#52395] Re: CRuby (Was: R) — Anders Bengtsson <ndrsbngtssn@...> 2002/10/03

Nikodemus Siivola wrote:

[#52400] Re: CRuby (Was: R) — Michael Campbell <michael_s_campbell@...> 2002/10/03

[#52402] Re: CRuby (Was: R) — Anders Bengtsson <ndrsbngtssn@...> 2002/10/03

Michael Campbell wrote:

[#52436] Specifying local and external block parameters (that old chestnut) — "Gavin Sinclair" <gsinclair@...>

I've cannibalised discussion from the "Bugs" thread. I hope it is a service to

49 messages 2002/10/04
[#52440] Re: Specifying local and external block parameters (that old chestnut) — matz@... (Yukihiro Matsumoto) 2002/10/04

Hi,

[#52610] Re: Specifying local and external block parameters (that old chestnut) — "MikkelFJ" <mikkelfj-anti-spam@...> 2002/10/06

[#52612] Re: Specifying local and external block parameters (that old chestnut) — ts <decoux@...> 2002/10/06

>>>>> "M" == MikkelFJ <mikkelfj-anti-spam@bigfoot.com> writes:

[#52557] Speed of Ruby/modruby vs PHP — Jim Freeze <jim@...>

Hi:

27 messages 2002/10/05
[#52598] Re: Speed of Ruby/modruby vs PHP — "MikkelFJ" <mikkelfj-anti-spam@...> 2002/10/06

[#52600] Re: Speed of Ruby/modruby vs PHP — Jim Freeze <jim@...> 2002/10/06

On Sun, Oct 06, 2002 at 08:50:48PM +0900, MikkelFJ wrote:

[#52601] Re: Speed of Ruby/modruby vs PHP — MoonWolf <moonwolf@...> 2002/10/06

> How do I configure mod_ruby to run with a cached script?

[#52628] Re: Speed of Ruby/modruby vs PHP — Jim Freeze <jim@...> 2002/10/06

Ok, here is how I understand this.

[#52636] Re: Speed of Ruby/modruby vs PHP — Jim Freeze <jim@...> 2002/10/06

On Sun, Oct 06, 2002 at 05:07:25PM -0400, Jim Freeze wrote:

[#52581] Platform again — Friedrich Dominicus <frido@...>

Well I ask again. On what platforms are you using ruby most of the

36 messages 2002/10/06

[#52602] Another take on ensuring right args to methods — Massimiliano Mirra <list@...>

11 messages 2002/10/06

[#52653] webforms — "Kontra, Gergely" <kgergely@...>

Hi!

19 messages 2002/10/07

[#52669] Things That Newcomers to Ruby Should Know — billtj@... (Bill Tj)

Hi,

59 messages 2002/10/07
[#52805] Re: Things That Newcomers to Ruby Should Know — "Bulat Ziganshin" <bulatz@...> 2002/10/09

Hello Bill,

[#52982] Re: Things That Newcomers to Ruby Should Know — "Kontra, Gergely" <kgergely@...> 2002/10/11

>3) 'x+=b', 'x*=b' and other assignment operators is internally translated

[#52727] block vars (some theory) — "Bulat Ziganshin" <bulatz@...>

Hello all,

37 messages 2002/10/08
[#52728] Re: block vars (some theory) — ts <decoux@...> 2002/10/08

>>>>> "B" == Bulat Ziganshin <bulatz@integ.ru> writes:

[#52806] strange Hash default behaviour — John Tromp <tromp@...>

I wrote a ruby program to read a list of graph edges and produce

16 messages 2002/10/09

[#52823] CGI sessions without cookies? — Stefan Scholl <stefan.scholl@...>

I haven't tried sessions, yet. But I'm curious if you can work

17 messages 2002/10/09

[#52848] Polymorphism, Isomorphism — ptkwt@...1.aracnet.com (Phil Tomson)

Consider this a bit of public pondering...

21 messages 2002/10/09

[#53045] Sorting — warren@... (Warren Brian Noronha)

dear developer,

31 messages 2002/10/12
[#53048] Re: Sorting — dblack@... 2002/10/12

Hello --

[#53082] Re: Sorting — "Mike Campbell" <michael_s_campbell@...> 2002/10/13

> I think almost anything is a better name than CRAN, as that (to me)

[#53083] Re: Sorting — dblack@... 2002/10/13

Hello --

[#53093] Re: Sorting — "Gavin Sinclair" <gsinclair@...> 2002/10/13

[#53109] Re: Sorting — "Mike Campbell" <michael_s_campbell@...> 2002/10/13

> Just a thought: why *not* copy CPAN? It's pretty good, isn't it?

[#53183] final in ruby — "Kontra, Gergely" <kgergely@...>

Hi!

21 messages 2002/10/14

[#53230] Please check my algorithm — Vincent Foley <vinfoley@...>

Hi, I found a nice programming challenge:

12 messages 2002/10/14

[#53278] ruby-dev summary 18458-18504 — TAKAHASHI Masayoshi <maki@...>

Hi all,

16 messages 2002/10/15

[#53285] Psyco — Travis Whitton <whitton@...>

There's an interesting article on IBM developerWorks about a new program

18 messages 2002/10/16

[#53297] Interfaces in Ruby — web2ed@... (Edward Wilson)

Is there a way to write/inforce interfaces in Ruby like one can using

44 messages 2002/10/16
[#53409] Re: Interfaces in Ruby — web2ed@... (Edward Wilson) 2002/10/17

>http://rm-f.net/~cout/code/ruby/treasures/RubyTreasures-0.3/lib/hacks/interface.rb.html

[#53470] Re: Interfaces in Ruby — Paul Brannan <pbrannan@...> 2002/10/17

On Thu, Oct 17, 2002 at 01:25:57PM +0900, Edward Wilson wrote:

[#53514] Re: Interfaces in Ruby — Massimiliano Mirra <list@...> 2002/10/18

On Fri, Oct 18, 2002 at 12:16:30AM +0900, Paul Brannan wrote:

[#53300] Re: Interfaces in Ruby — Chris Gehlker <canyonrat@...> 2002/10/16

[#53334] Re: Interfaces in Ruby — Paul Brannan <pbrannan@...> 2002/10/16

On Wed, Oct 16, 2002 at 01:30:04PM +0900, Chris Gehlker wrote:

[#53359] Things That Newcomers to Ruby Should Know (10/16/02) — William Djaja Tjokroaminata <billtj@...>

Hi,

29 messages 2002/10/16
[#53774] Re: Things That Newcomers to Ruby Should Know (10/16/02) — "Hal E. Fulton" <hal9000@...> 2002/10/22

----- Original Message -----

[#53556] Help wanted with an experimental FAQ facility — Dave Thomas <Dave@...>

24 messages 2002/10/18

[#53626] XMLParser, NQXML, REXML, ... — Armin Roehrl <armin@...>

Hi XML-freaks,

23 messages 2002/10/20
[#53897] Re: XMLParser, NQXML, REXML, ... — Sean Chittenden <sean@...> 2002/10/23

> Hi XML-freaks,

[#53902] Ruby.bah! (was Re: XMLParser, NQXML... and also RAA.succ) — Austin Ziegler <austin@...> 2002/10/23

On Wed, 23 Oct 2002 13:01:59 +0900, Sean Chittenden wrote:

[#53904] Re: Ruby.bah! (was Re: XMLParser, NQXML... and also RAA.succ) — Sean Chittenden <sean@...> 2002/10/23

> > Markus and I are working on rubydoc which is now able to

[#53911] Re: Ruby.bah! (was Re: XMLParser, NQXML... and also RAA.succ) — Austin Ziegler <austin@...> 2002/10/23

On Wed, 23 Oct 2002 14:07:46 +0900, Sean Chittenden wrote:

[#53652] RAA.succ? — ptkwt@...1.aracnet.com (Phil Tomson)

I hope there will be some discussion of RAA.succ (or is it RAA.next) at

78 messages 2002/10/21
[#53654] Re: RAA.succ? — nobu.nokada@... 2002/10/21

Hi,

[#53669] Re: RAA.succ? — "NAKAMURA, Hiroshi" <nahi@...> 2002/10/21

Hi,

[#54022] RAA replaced — "NAKAMURA, Hiroshi" <nahi@...> 2002/10/24

Hi,

[#53914] Re: RAA.succ? (rpkg vs rubynet) — ptkwt@...1.aracnet.com (Phil Tomson) 2002/10/23

In article <20021023041621.GC48080@perrin.int.nxad.com>,

[#53688] functional Ruby equiv to this perl snippet — bobx@... (Bob)

# parses a text file looking for server names and ignoring lines

29 messages 2002/10/21
[#53694] Re: functional Ruby equiv to this perl snippet — Austin Ziegler <austin@...> 2002/10/21

def load_server_list

[#53696] Re: functional Ruby equiv to this perl snippet — Austin Ziegler <austin@...> 2002/10/21

I realised that my first test wasn't good for non-empty but blank

[#53718] Re: functional Ruby equiv to this perl snippet — "Bob X" <bobx@...> 2002/10/21

"Austin Ziegler" <austin@halostatue.ca> wrote in message

[#53703] rb_gc_register_address problem — Paul Brannan <pbrannan@...>

We ran into a problem today with the garbage collector (caused by our

28 messages 2002/10/21

[#53771] Perl multiple match RE in Ruby? — michael libby <x@...>

-----BEGIN PGP SIGNED MESSAGE-----

14 messages 2002/10/22

[#53865] XMLRPC and IP authentication — Daniel Berger <djberge@...>

Hi all,

13 messages 2002/10/22

[#53884] SQLite — "Bob X" <bobx@...>

Anyone working on a Ruby interface for SQLite?

109 messages 2002/10/23
[#53894] Re: SQLite — Austin Ziegler <austin@...> 2002/10/23

On Wed, 23 Oct 2002 10:38:31 +0900, Bob X wrote:

[#54714] Thoughts on Ruby — Enric Lafont <enric@1smart.com> 2002/11/03

Hi all,

[#54724] Re: Thoughts on Ruby — Albert Wagner <alwagner@...> 2002/11/03

On Saturday 02 November 2002 7:57 pm, Enric Lafont wrote:

[#54725] Re: Thoughts on Ruby — Austin Ziegler <austin@...> 2002/11/03

On Sun, 3 Nov 2002 10:57:29 +0900, Enric Lafont wrote:

[#54784] Re: Thoughts on Ruby — Enric Lafont <enric@1smart.com> 2002/11/03

Austin Ziegler wrote:

[#54802] Re: Thoughts on Ruby — Austin Ziegler <austin@...> 2002/11/03

On Mon, 4 Nov 2002 06:44:46 +0900, Enric Lafont wrote:

[#54826] Re: Thoughts on Ruby — "Gavin Sinclair" <gsinclair@...> 2002/11/04

From: "Enric Lafont" <enric@1smart.com>

[#54903] Re: Thoughts on Ruby — Brian Candler <B.Candler@...> 2002/11/05

On Mon, Nov 04, 2002 at 10:02:12PM +0900, Gavin Sinclair wrote:

[#54920] Re: Thoughts on Ruby — Austin Ziegler <austin@...> 2002/11/05

On Tue, 5 Nov 2002 20:18:47 +0900, Brian Candler wrote:

[#54927] Re: Thoughts on Ruby lack of IDE — Brad Cox <bcox@...> 2002/11/05

It is a sign of my hybrid Objective-C background, no doubt, but I

[#54929] Re: Thoughts on Ruby lack of IDE — "Curt Hibbs" <curt@...> 2002/11/05

Brad Cox wrote:

[#55322] FreeRIDE and FUI ?? (was: Re: Thoughts on Ruby lack of IDE) — "Rich" <rich@...> 2002/11/08

> > >

[#55346] Re: FreeRIDE and FUI ?? (was: Re: Thoughts on Ruby lack of IDE) — "Rich Kilmer" <rich@...> 2002/11/09

> -----Original Message-----

[#53953] Re: Things That Newcomers to Ruby Should Know (10/16/02) — "Mills Thomas (app1tam)" <app1tam@...>

But why does it really, REALLY mean that? Was there a reason for doing

13 messages 2002/10/23

[#53957] NODE tree introspection — Simon Cozens <simon@...>

13 messages 2002/10/23

[#53983] Re: Things That Newcomers to Ruby Should Know (10/16/02) — "Mills Thomas (app1tam)" <app1tam@...>

Actually, the way you describe '+=' makes sense to me. It is what I would

17 messages 2002/10/23
[#54001] Re: Things That Newcomers to Ruby Should Know (10/16/02) — William Djaja Tjokroaminata <billtj@...> 2002/10/23

Hi,

[#54012] Re: Things That Newcomers to Ruby Should Know (10/16/02) — dblack@... 2002/10/24

Hi --

[#54111] How come true, false don't support <=> (comparison) operator? — cilibrar@... (Rudi Cilibrasi)

I am wondering if there is a good reason why Ruby does not by default

24 messages 2002/10/25
[#54112] Re: How come true, false don't support <=> (comparison) operator? — dblack@... 2002/10/25

Hello --

[#54139] Re: How come true, false don't support <=> (comparison) operator? — ptkwt@...1.aracnet.com (Phil Tomson) 2002/10/25

In article <Pine.LNX.4.44.0210250754010.2650-100000@candle.superlink.net>,

[#54156] Re: How come true, false don't support <=> (comparison) operator? — dblack@... 2002/10/25

Hi --

[#54239] Snippet request: Ruby Web Server written in under an hour — Phlip <phlipcpp@...>

Rubies:

37 messages 2002/10/28
[#54328] Snippet: Tiny Featureless Ruby Web Server — Phlip <phlipcpp@...> 2002/10/29

Rubies:

[#54339] method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) — dblack@... 2002/10/29

Hi --

[#54517] Re: method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) — William Djaja Tjokroaminata <billtj@...> 2002/10/30

Bulat Ziganshin <bulatz@integ.ru> wrote:

[#54519] Re: method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) — dblack@... 2002/10/30

Hi --

[#54525] Re: method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) — William Djaja Tjokroaminata <billtj@...> 2002/10/30

dblack@candle.superlink.net wrote:

[#54527] Re: method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) — dblack@... 2002/10/30

Hi --

[#54280] exerb & fox-problem; converting gui-script to .exe on windows — Armin Roehrl <armin@...>

Hi,

12 messages 2002/10/28

[#54354] good link to read as we contemplate RAA, RAA.succ, et al — Pat Eyler <pate@...>

http://www.onlamp.com/pub/wlg/2225

28 messages 2002/10/29
[#54356] Re: good link to read as we contemplate RAA, RAA.succ, et al — dblack@... 2002/10/29

Hi --

[#54385] Re: good link to read as we contemplate RAA, RAA.succ, et al — " JamesBritt" <james@...> 2002/10/29

> Interesting. Simon (hi Simon!) is probably right that "Definitive

[#54421] want to meet Microsoft .NET guy? — matz@... (Yukihiro Matsumoto)

Hi,

17 messages 2002/10/30

[#54449] feature idea: custom literals — loats205@... (loats205)

wouldn't it be cool if you could define custom literal representations for your

30 messages 2002/10/30
[#54459] Re: feature idea: custom literals — Peter Hickman <peter@...> 2002/10/30

loats205 wrote:

[#54476] Re: feature idea: custom literals — Nikodemus Siivola <tsiivola@...> 2002/10/30

Re: Mail filter (was RE: announce@ == less email (FAQ item?))

From: <bbense+comp.lang.ruby.Oct.08.02@...>
Date: 2002-10-08 14:50:10 UTC
List: ruby-talk #52748
-----BEGIN PGP SIGNED MESSAGE-----

In article <anmco6$ffo3l$1@ID-57631.news.dfncis.de>,
Stefan Schmiedl  <s@xss.de> wrote:
>On Sat, 5 Oct 2002 16:14:53 +0900,
>Pe, Botp <botp@delmonte-phil.com> wrote:
>> 
>> 
>>> Stefan Schmiedl [mailto:s@xss.de] explains
>>>
>>>> >> Julian Fitzell [mailto:julian@beta4.com] enlightens
>>> >> 
>>> >> ...
>>> >> accept if message.subject =~ /Ruby Weekly News/i
>>> >> accept if message.subject =~ /ruby-dev summary/i
>>> >> ...
>>> >> 
>>> 
>>> It seems to be a handmade replacement of the
>>> fetchmail - procmail toolchain on linux.
>>> 
>> Yes. I've seen procmail scripts, and they don't come close...
>> 
>> I hope he'd share it though ;-)
>> 
>
>Well, it's not that difficult ... when I upgraded
>my box last week, the new version of fetchmail got
>confused by something in the first message of the
>mailbox, so I took a look at net/smtp.rb (IIRC),
>and fumbled something together to take a closer look.
>
>However, a simultaneously performed downgrade of
>fetchmail did the job, too, so I stopped tinkering.
>
>It is very easily doable, as long as your output
>is easy to manage, like appending to different files.
>
>Go on, do it yourself ... or investigate at RAA.
>
>s.


- - Here's mine. It's got a whole bunch of wierd stuff in it since
  I need to read my email out of NFS and write it into AFS. It
  uses ifile and the rmail and rfilter modules, but it might
  give you some ideas. I've found the rmail/rfilter stuff pretty
  useful. 

- - Booker C. Bense 

#!/var/local/bin/ruby
# Get the Mailspool and process it. 
#
#

require 'rmail/parser'
require 'rmail/parser/mbox' 
require 'tempfile'

require 'rfilter/deliver'

# Manage Ifile interactions

#
# $Id: ifile.rb,v 1.1 2002/09/25 20:02:13 bbense Exp $
#
# Ifile, a class for interacting with ifile program.
# Get ifile at http://www.ai.mit.edu/~jrennie/ifile/
#
# Booker C. Bense <bbense@slac.stanford.edu> 
#

require 'open3'

module Ifile

# This is the wrong name, but I can't think of anything better.
class Process
  # Tell me where ifile lives.
  def initialize(path="/var/local/bin/ifile",args="--verbosity=0") 
    if FileTest.executable?(path) then 
      @ifile = path
      @args = args
    else
      raise ArgumentError 
    end 
  end

  # Given a message, query folders

  def query(msg)
    results = Array.new
    output = self.run_ifile(msg,"--query ")
    i = 0 
    output.each do |line|
      # Format of output is folder score
      folder , score = line.split
      if ( folder && score ) then 
	tmp = Hash.new
	tmp['folder'] = folder
	tmp['score'] = score.to_f
	tmp['position'] = i 
	results << tmp 
	i = i + 1 
      end
    end 
    return results
  end 

  # Add a message to a folder
  def add(msg,folder)
    output = self.run_ifile(msg,"--insert=#{folder}") 
  end
  # Delete a message from a folder
  def delete(msg,folder) 
    output = self.run_ifile(msg,"--delete=#{folder}") 
  end 

  # Refile
  def refile(msg,oldfolder,newfolder) 
    self.delete(msg,oldfolder) 
    self.add(msg,newfolder)
  end 
# internal methods
  
  
  def run_ifile(msg,args) 
    stdin, stdout, stderr = Open3.popen3("#{@ifile} #{@args} #{args}")
    #write msg to ifile
    msg.each { |line| stdin.puts line } 
    stdin.close
    #Read output 
    output = stdout.readlines
    stdout.close
    stderr.close
    return output
  end 


end


end # module Ifile
 

class MailSpool 
  # Set the spool name
  def initialize(user,path="/var/spool/mail/")
    if ( user == nil ) then
    	user = Etc.getpwuid(Process.uid).name	
    end
    @spool = File.open("#{path}#{user}","r+");   
    @tmpspool = Tempfile.new("mailspool") 
    @parser = RMail::Parser.new
    @mreader = RMail::Parser::MBoxReader.new(@tmpspool)
  end
  # Move the spool to tmpspool 

  def update
    begin
      if @spool.stat.size > 0 then
	# Lock the spool file	
	@spool.flock(File::LOCK_EX) 
	# Read it in 
	@spool.rewind
	new_msgs = @spool.read
	# Empty it.
	@spool.truncate(0)
        # Unlock it 
	@spool.flock(File::LOCK_UN)
	@tmpspool.truncate(0)
	# Write it out to tmpspool
	@tmpspool.write(new_msgs)
        @tmpspool.close
      return true
     else
      return nil
     end 
    rescue 
      return nil
    end
  end

  # Return an array of messages. 
  def messages
    @tmpspool.open
  
    messages = []
    loop do
      msg = @parser.parse(@mreader.next)
      if msg.header.mbox_from then
	messages << msg
      else
	break
      end
    end
    messages
  end  

end 

# These are really HeaderFilters. 
class Filter
  
  # remember the regexp test and the folder it maps to. 
  def initialize ( test, folder ) 
    @test = test
    @folder = folder
    @has_proc = nil
  end 

  def test
    @test
  end 

  def folder
    @folder
  end

  def has_proc?
    @has_proc
  end
  
# This proc is for after a successful match to do 
# dynamic folder setting. 
  def addProc(proc)
    if defined? proc.call then 
      @proc = proc
      @has_proc = true
    else
      raise ArguementError
    end
  end 

  def call(msg) 
    @proc.call(msg)
  end

end 

# Return a string that indicates a folder to file into. 
# Add auto month splitting ? 
class FilterProcess 

 def initialize(user, filterdir, default_folder="incoming" )
   @user = user
   @default_folder = "#{filterdir}/#{default_folder}"
   @filterdir = filterdir

#   Switch to using date folder for auto month rollover
#   @folderdir = "#{filterdir}/Now"
   tmp = Time.now.asctime
   tmpfolder = tmp.split[1] + tmp.split[4]
   @folderdir = "#{filterdir}/#{tmpfolder}"
   @logfile = File.open("#{filterdir}/log.#{tmpfolder}","a")

   @filters = Hash.new
   @filterKeys = Array.new
 end

 def default_folder
   @default_folder
 end

 def folderdir
   @folderdir
 end

 def addFilter(filter,type='envelope') 
   my_type = 'envelope' unless type 
   if ( filter.test.respond_to?(:match) ) && ( defined? filter.folder ) then
     if @filters.has_key? my_type then
       @filters[my_type] << filter
     else 
       @filters[my_type] = Array.new
       @filters[my_type] << filter
       @filterKeys << my_type
     end 
   else
     raise ArgumentError 
   end 
 end

 def process(msg)
   if msg.header then 
     @filterKeys.each do |key| 
       if msg.header.mbox_from && ( key == 'envelope')  then
	 test_string = msg.header.mbox_from
       else 
	 test_string = msg.header[key]
       end
       if test_string then 
	 activeFilter = @filters[key].detect { |filter| filter.test.match(test_string) }
	 if activeFilter then
	   if activeFilter.has_proc? then
	     folder = activeFilter.call(msg)
	     if folder then
	       return "#{@folderdir}/#{folder}"
	     end
	   else
	     # Wrong place to do logging.
	     # self.log("Filing #{msg.header['message-id']} in #{activeFilter.folder}")
	     return "#{@folderdir}/#{activeFilter.folder}"
	   end
	 end
       end
     end #filterKeys
   end #msg.header
   return @default_folder
 end 

 def log (string)
   print "#{string}\n" if ( string =~ /ERROR/ ) 
   @logfile.print "#{string}\n"
 end 

 def initFilters
   filterfile = "#{@filterdir}/filters"
   begin
     File.open(filterfile) do |file|
       while ( line = file.gets ) do 
	 unless ( line =~ /^#/ ) then
	   flag_string , mbox , type = line.split
	   if ( flag_string && mbox ) then
	     self.addFilter(Filter.new(Regexp.new(Regexp.quote(flag_string)),mbox),type) 
	   end
	 end
       end
     end
   rescue
     print "Error in reading #{filterfile}"
     exit
   end
 end 

end #FilterProcess

# For dealing with file
class IfileProcess

  def initialize(filterdir,default_folder)
    @filterdir = filterdir
    @default_folder = default_folder
    @ifile = Ifile::Process.new
    @same = Hash.new
    @same["unix-admin"] = "oldmail"
    @same["admin-log"]  = "oldmail"
    @same[default_folder] = "oldmail"
  end

# Return a full fledge path 
  def query(msg)
    results = @ifile.query(msg) 
    best = results[0]["folder"]
    # Where did oldmail score
    # oldmail = results.detect { |result| result["folder"] == "oldmail" }
    if ( best == "oldmail" ) then
      return @default_folder
    end 
    dest = "#{@filterdir}/#{best}"
    dest.sub!(/\s/,"")
    return dest
  end 

  def add(msg,destination)
    if ( @same[destination] ) then
      folder = @same[destination]
    else
      folder = destination.sub(@filterdir,"")
      folder.sub!(/[\/]/,"")
      # Deal with incoming/oldmail problem 
      if ( @same[folder]  ) 
	folder = @same[folder] 
      end
    end
#    print "Adding message to :#{folder}:\n"
    @ifile.add(msg,folder)
  end

end #IfileProcess

# This is for real.
begin 
  filterP = FilterProcess.new("foobar","/home/foobar/filtermail")

  begin 
    # Be more paranoid add a timestamp and pid
    backup = "/tmp/foobar.backupspool.#{Time.now.to_i}.#{Process.pid}"
    system("/bin/cp /var/spool/mail/foobar #{backup}")
  rescue
    print "Error making backup... /tmp/foobar.backsupspool"
    exit 
  end 
  emergency = "/tmp/foobar.emergency"

  spool = MailSpool.new("foobar")
  filterP.initFilters

#Ifile interface. 
  ifile = IfileProcess.new(filterP.folderdir,filterP.default_folder)

rescue => error
  print "Error in startup. #{error.inspect}\n"
  exit
end

report = Hash.new(0)

if ( spool.update) then 
  messages = spool.messages

  messages.each do |msg|
    # Where does it go ? 
    destination = filterP.process(msg)
    # Do some destination dependant checks. 
    if ( destination == filterP.default_folder ) then
      begin
	new_destination = ifile.query(msg)
        filterP.log("INFO: Ifile redirect #{destination} => #{new_destination}")
	destination = new_destination
      rescue
	filterP.log("ERROR: using ifile.query") 
      end
    end
    report[destination] = report[destination] + 1  
    # Write to destination
    filterP.log("INFO: Filing #{msg.header['message-id']} in #{destination}")
    # Check for error
    begin
      RFilter::Deliver.deliver_mbox(destination,msg)
    rescue
      RFilter::Deliver.deliver_mbox(emergency,msg)
      filterP.log("ERROR: Delivering to #{emergency}")
    end
    # Add to ifile database. 
    begin
      ifile.add(msg,destination)
    rescue => error
      filterP.log("ERROR: using ifile.add #{error.inspect}") 
    end 
  end
end

# print report
report.each do |folder, count|
  print "#{folder} : #{count} new messages\n"
end


-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBPaLtDWTWTAjn5N/lAQHBvAP/Zg5+4Zh8qPNQuHg98naoktqzhovZh4ws
61wlZzsQ13SKStl40hF3TqS7x2BbvgYNJnl9r5iC6qXpraxByQVU59yntEY3HP14
22LPvL3r3rIxgzbbO0sQ7mCF2s/Gw4wVfk0xHxgM4zSjZ9uKqNz3KdS8B0eKtUR3
TTSGrodsN6g=
=AaZQ
-----END PGP SIGNATURE-----

In This Thread

Prev Next