Solved

MIME-parts and JavaMail

Posted on 2003-11-03
11
484 Views
Last Modified: 2013-11-24
Hello

I'm doing an email client with JavaMail and I got a question regarding storing the email-messages.

I would like to write a modul called 'Store' for my program, that does the following.

1) Then this modul recieves an email it would like to split it up into MIME-parts (From, id, mailbody) etc. I would like these parts to be stored in a MySQLDB.

2) Is it possible to add feature that reassembles these MIME-parts into a readable email ?

I hope that there are someone of You, how can answer these questions for me !

Yours
Frank
0
Comment
Question by:Frank-22
  • 6
  • 4
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9673665
Just look at the Part/MimePart interface. If you decompose the mail into its parts you can write it to a db, possibly with the assistance of serialization and ObjectOutputStream. Each Part should be renderable on the symmetrical read operation with ObjectInputStream.
0
 

Author Comment

by:Frank-22
ID: 9673795
Yeah,

I know I can do this to decode the message.

MimePart part = ...
  String rawvalue = null;
  String  value = null;
  try {
    if ((rawvalue = part.getHeader("X-mailer")[0]) != null)
      value = MimeUtility.decodeText(rawvalue);
  } catch (UnsupportedEncodingException e) {
      // Don't care
      value = rawvalue;
  } catch (MessagingException me) { }

  return value;

But how do I save these MIME-parts into a MYSQLDB, and Reassemble them into an readable email ?

The reason for me asking is because I have looked through all the books I have at home for a method on how to do this, but have been unable to find any !!!

And I promissed someone, that I could do this easily and present a working modul tommorow !

So it would "really" appricate if You could show me how to do it !!

Frank  
0
 

Author Comment

by:Frank-22
ID: 9674106
Hi

As of now my Store-Modul looks the code below.

I'm uanable to get the store-feature to function.

What I'm I doing wrong ? How do I get it to work ?

Frank

package modmail.store;
import javax.mail.*;
import modmail.listener.*;
import java.sql.*;

public class mySQL implements GuiListener, ReceiveListener
{
    private Connection connectionToDB;
    private String password = "";
    private String login = "";
    private String selectDB = "";

    //Start of RecieveListener's methods
    public void saveSuccessful(boolean b, String[] arrayOfMailID, int errorcode)
    {
    }

    public void hasNewMail(String[] arrayOfMailID)
    {
    }
    //End of RecieveListener's methods

    //Start of GuiListener's methods

    /** Is activated when the button "Send" is pressed on the GUI.  */
    public void sendButtonClicked()
    {
      //Do nothing
    }

    public void reciveButtonClicked()
    {
    }
   
    public void loadMail()
    {
    }

    public void saveMail()
    {
    }
   
    public void deleteMail()
    {
    }
   
    public void undeleteMail()
    {
    }

    public void printMail()
    {
      //Do nothing
    }
    //End of GuiListener's methods

    private void connectToDb()
    {
      /** Temporaty code to login, get login info from config file later */
      if(password == "" || login == "" || selectDB == "")
          {
            password = "e3110";
            login = "root";
            selectDB = "//localhost/movieDB";
          }
      try{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connectionToDB = DriverManager.getConnection("jdbc:mysql:" + selectDB + "?user=" + login + "&password=" + password);
      }catch(Exception e){}
    }

    /** Adds an email to the mail database. */
    /*
    public void addEntry(Message mail) throws Exception
    {
      Statement stmt = null;
      String query = "";
      String subject = mail.getSubject();
      Date sendDate = mail.getSendDate();
      String fromEmail = (mail.getSender()).toString();
      Address[] replyToAdd = mail.getReplyTo();
      String[] replyTo = new String[replyToAdd.length];
      for(int i = 0; i > replyToAdd.length; i++)
          {
            replyTo[i] = replyToAdd.toString();
          }
      Date recievedDate = mail.getRecievedDate();
      String body = ""; // WRU real body txt?!?
      int ID = mail.getMessageID();
      stmt = connectionToDB.createStatement();
      stmt.executeUpdate(query);
      stmt = null;
    }
    */
}
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 86

Expert Comment

by:CEHJ
ID: 9674149
And what seems to be the problem?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9674416
(almost) never have this sort of thing:


>>catch(Exception e){}
0
 

Expert Comment

by:Euroman_21
ID: 9676516
I get an unrecognized type every time I try to add !

Is there a better way of doing it than I'm allready doing it now ?

Sincerely

Frank

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9677927
All I can see of your statement is the following:

>>String query = "";

What is it meant to be - what will your SQL be?
0
 

Author Comment

by:Frank-22
ID: 9678682
Hi and thank You for Your answer.

As You correctly singled out the String query = ""; is empty, that is because I can not get the sql query, that was suppose to insert the MiME-parts into the mySQL db.

I know how to make an sql - query, but unfornally not in this context.

So I would really appricate if You have a surgestion on how You think this SQL-Query should sound ?

Sincerely
Frank  

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9678777
The first thing you need to do is have a table with columns in it to take all the pieces of data you want to save. You would then do an INSERT statement
0
 

Author Comment

by:Frank-22
ID: 9678977
Okay....

I got a table called maildb (movieDB is a typoo) would this be a correct query ?

String query = "insert into maildb (subject, sendDate, fromEmail) values ('" + mail.getSubject() + "','" + mail.getSendDate() + "','" + (mail.getSender()).toString() + "')";


Sincerely

Frank
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 9679048
Yep, looks OK.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question