Solved

MIME-parts and JavaMail

Posted on 2003-11-03
11
486 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in @AspectJ Based AOP with Spring 2 24
servlet example 17 59
hibernate example issues from command prompt 10 65
JavaFX TableView not displaying correctly 3 109
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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