class to read an email from net/pop3 ?

Discussion in 'Ruby' started by Stephane Wirtel, Oct 16, 2005.

  1. Hi all,

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

    Thank you,

    Stephane
     
    Stephane Wirtel, Oct 16, 2005
    #1
    1. Advertising

  2. Robert Klemme, Oct 16, 2005
    #2
    1. Advertising

  3. > 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)).

    To separate each field of the header, and to create a small database.

    And why not, create a small gui with gtk2.

    Stef
     
    Stephane Wirtel, Oct 17, 2005
    #3
  4. Tim Hammerquist wrote:
    > Stephane Wirtel <> wrote:
    >> Is there a library to read emails (rfc822) stored in a mailbox
    >> or a maildir ?

    >
    > 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,
     
    Stephane Wirtel, Oct 17, 2005
    #4
  5. Read a Mail Box in mbox format (was: Re: class to read an email from net/pop3 ?)

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


    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
     
    Robert Klemme, Oct 17, 2005
    #5
  6. ------=_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 <http://www.rfidnewsupdate.com> Simple,
    fast, news.

    ------=_Part_3627_15219881.1129591760071--
     
    Lyndon Samson, Oct 18, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Becker

    pop3 email header classifier?

    Robin Becker, Sep 19, 2003, in forum: Python
    Replies:
    6
    Views:
    422
    David Mertz
    Sep 23, 2003
  2. Paul Schmidt

    POP3 and email

    Paul Schmidt, Jun 6, 2004, in forum: Python
    Replies:
    4
    Views:
    440
    Larry Bates
    Jun 9, 2004
  3. moni
    Replies:
    7
    Views:
    1,717
    Greg R. Broderick
    Oct 6, 2007
  4. dale
    Replies:
    14
    Views:
    304
    Brandon Metcalf
    Dec 14, 2004
  5. Ted Byers
    Replies:
    0
    Views:
    256
    Ted Byers
    Mar 20, 2009
Loading...

Share This Page