class to read an email from net/pop3 ?

S

Stephane Wirtel

Hi all,

Is there a library to read emails (rfc822) stored in a mailbox or a
maildir ?

Thank you,

Stephane
 
S

Stephane Wirtel

Tim said:
It's difficult to figure out what you want. Your subject
says "net/pop3", but the body seems to imply the messages are
stored on a local filesystem.

Tim
Hi Tim,

Yes, sorry. In fact, I would like to create a small client to retrieve
my mail from my isp, and to store each mail into a database.

So, with which library can I analyze the header ?

Stef,
 
R

Robert Klemme

Stephane Wirtel said:
:) Thanks for this documentation, but in fact, I want to store my
emails in a rdbms (postgresql, ... (why not sqlite3)).

Please choose a less misleading subject next time.
To separate each field of the header, and to create a small database.

This might help.
http://www.dagbrown.com/software/gurgitate-mail/

For the database there's a lot of tools around (starting from DBD/DBI, a
standard DB interface) to more sophisticated things like ActiveRecord etc.
Depends on your needs.
And why not, create a small gui with gtk2.

I'm not so into GUI programming but I'm sure someone else will provide
pointers. I'm sure you'll also find them easily via Google.

Regards

robert
 
L

Lyndon Samson

------=_Part_3627_15219881.1129591760071
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

:) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top