From: Lyndon Samson Date: 2005-10-18T08:29:22+09:00 Subject: Re: class to read an email from net/pop3 ? ------=_Part_3627_15219881.1129591760071 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 10/18/05, Stephane Wirtel wrote: > > > require 'net/pop' > > ... > > > > http://www.ruby-doc.org/stdlib/libdoc/net/pop/rdoc/index.html > > > :-) Thanks for this documentation, but in fact, I want to store my > emails in a rdbms (postgresql, ... (why not sqlite3)). Great minds think alike!!! :-) I'm working on this as well. Here's my initial attempt with the oblig disclaimer that it needs lots of further work! require 'sqlite3' class FileDataSource def initialize(name) #@lines =3D IO.readlines(name); @file =3D File.open(name) end def getLine #return @lines.shift @file.gets end end def processMessage(cnt, db, message) fldFrom=3D"" fldTo=3D"" fldSubject=3D"" fldDate=3D"" message.each { |lne| if lne =3D~ /^From: (.*)/ fldFrom =3D $1 end if lne =3D~ /^To: (.*)/ fldTo =3D $1 end if lne =3D~ /^Subject: (.*)/ fldSubject =3D $1 end if lne =3D~ /^Date: (.*)/ fldDate =3D $1 end } db.prepare "insert into email ( 'Id', 'From','To','Subject','Date','Message= ' ) values ( ?, ?, ?, ?, ?, ?)" do |stmt| stmt.bind_params cnt, fldFrom, fldTo, fldSubject, fldDate,SQLite3::Blob.new= ( message.to_s ) stmt.execute end puts "Added Record #{cnt} Subject:#{fldSubject}" end dataSource =3D FileDataSource.new("ozemail.inbox") cnt =3D 0 db =3D SQLite3::Database.open( "sqllite\\demo.db", :driver =3D> "Native" ) message =3D [] while line =3D dataSource.getLine if line =3D~ /^From / cnt+=3D1 processMessage(cnt, db, message) message =3D [] else message << line end end db.close -- Into RFID? www.rfidnewsupdate.com Simple, fast, news. ------=_Part_3627_15219881.1129591760071--