Solved

MIME-parts and JavaMail

Posted on 2003-11-03
11
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

729 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