[#6864] ruby 1.8.4 rc breaks alias_method/rails in bad ways — "Ara.T.Howard" <ara.t.howard@...>

20 messages 2005/12/09
[#6870] Re: ruby 1.8.4 rc breaks alias_method/rails in bad ways — =?ISO-8859-15?Q?Florian_Gro=DF?= <florgro@...> 2005/12/12

Ara.T.Howard wrote:

[#6872] Re: ruby 1.8.4 rc breaks alias_method/rails in bad ways — ara.t.howard@... 2005/12/12

On Tue, 13 Dec 2005, [ISO-8859-15] Florian Growrote:

[#6873] Re: ruby 1.8.4 rc breaks alias_method/rails in bad ways — James Edward Gray II <james@...> 2005/12/12

On Dec 12, 2005, at 1:19 PM, ara.t.howard@noaa.gov wrote:

[#6874] Re: ruby 1.8.4 rc breaks alias_method/rails in bad ways — ara.t.howard@... 2005/12/12

On Tue, 13 Dec 2005, James Edward Gray II wrote:

[#6891] Time.utc! and Time.localtime! — Daniel Hobe <hobe@...>

Writing a script yesterday I found out, much to my surprise, that the

16 messages 2005/12/14

[#6918] change to yaml in 1.8.4 — ara.t.howard@...

14 messages 2005/12/16

[#6934] 1.8.x, YAML, and release management — Ryan Davis <ryand-ruby@...>

I'm concerned that 1.8.3's acceptance of non-backwards-compatible

28 messages 2005/12/18

[#6996] Problems building 1.8.4 with VS8 C++ Express Edition (cl 14.00) — Austin Ziegler <halostatue@...>

Visual Studio C++ 2005 Express Edition (VS 8.0)

20 messages 2005/12/27

bug in mailread.rb, and: proposal for Mail#to_s

From: Wybo Dekker <wybo@...>
Date: 2005-12-04 12:46:44 UTC
List: ruby-core #6828
mailread separates mail messages looking for /^From /.
This is incorrect, because message bodies may contain lines beginning with

From like this mail does. So the regexp should be, I think, something 
like: /^From .*? \w{3} \w{3} [\d ]{2} \d\d:\d\d:\d\d \d{4}/

I also propose a to_s method, which converts the Mail object to a 
(possibly edited) copy of the original mail message. 

The attached maildir.rb is my proposal for both topics. 

-- 
Wybo

Attachments (1)

mailread.rb (1.55 KB, text/x-ruby)
class Mail

  def initialize(f)
    unless defined? f.gets
      f = open(f, "r")
      opened = true
    end

    @header = {}
    @body = []
    begin
      while line = f.gets()
	line.chop!
	next if /^From /=~line	# skip From-line
	break if /^$/=~line	# end of header

	if /^(\S+?):\s*(.*)/=~line
	  (attr = $1).capitalize!
	  @header[attr] = $2
	elsif attr
	  line.sub!(/^\s*/, '')
	  @header[attr] += "\n" + line
	end
      end
  
      return unless line

      while line = f.gets()
        # From wybo@servalys.nl Sun Sep 26 13:20:51 2004 +0200
	break if /^From .*? \w{3} \w{3} [\d ]{2} \d\d:\d\d:\d\d \d{4}/=~line
	@body.push(line)
      end
    ensure
      f.close if opened
    end
  end

  def header
    return @header
  end

  def body
    return @body
  end

  def [](field)
    @header[field.capitalize]
  end

  # Return a Mail object, ready to print, including a `From ' line.
  # Header tags will appear sorted, but Date, From, Subject and To 
  # go in front; note that of tags that occurred multiply times in the
  # original (like Received:), only the last one will be reproduced here
  def to_s
    prior = %w{Date From Subject To}
    s = "From mailread.rb #{DateTime.now.asctime}" + $/ 
    self.header.keys.sort { |a,b|
      if prior.index(a)
        prior.index(b) ? a <=> b : -1
      elsif prior.index(b)
        1
      else
        a <=> b
      end
    }.each { |k|
      s << "#{k}: #{self.header[k].gsub(/#{$/}/,$/+"\t")}" + $/
    }
    s << $/
    s << self.body.join
  end

end

In This Thread

Prev Next