0% found this document useful (0 votes)
22 views19 pages

New Text Document

Uploaded by

ajay khanduri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views19 pages

New Text Document

Uploaded by

ajay khanduri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 19

import java.awt.

BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;
import java.awt.Color;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Properties;
import java.util.Vector;
import java.util.regex.Matcher;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import com.aspose.email.EmlSaveOptions;
import com.aspose.email.FileFormat;
import com.aspose.email.FolderInfo;
import com.aspose.email.FolderInfoCollection;
import com.aspose.email.MailMessage;
import com.aspose.email.MailMessageSaveType;
import com.aspose.email.MailStorageConverter;
import com.aspose.email.MapiAttachmentCollection;
import com.aspose.email.MapiMessage;
import com.aspose.email.MboxrdStorageReader;
import com.aspose.email.MessageInfo;
import com.aspose.email.MessageInfoCollection;
import com.aspose.email.OlmStorage;
import com.aspose.email.PersonalStorage;
import com.aspose.email.SaveOptions;
import com.aspose.email.StandardIpmFolder;
import com.aspose.email.system.io.FileAccess;
import com.aspose.email.system.io.FileMode;
import com.aspose.email.system.io.FileStream;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JTextArea;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JProgressBar;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import com.toedter.calendar.JDateChooser;
import javax.swing.JComboBox;
import java.awt.Label;

public class Main_Frame extends JFrame {

private JPanel contentPane;


private static JTextField tf_FileChooser;
static JFileChooser jFileChooser;

static JFileChooser jFileChooser_destination;


JRadioButton rdbtn_input_Mbox;
static PersonalStorage pst;
static String destination_path;
JComboBox comboBox_fileDestination_type;
JRadioButton rdbtn_SingleFile;
JRadioButton rdbtn_MultipleFile;
JRadioButton rdbtn_input_ost;
JRadioButton rdbtn_input_pst;
JRadioButton rdbtn_input_edb;
int j=0;
Date da;
Date df;
String date;
JDateChooser dateChooser_mail_fromdate;
JDateChooser dateChooser_mail_tilldate;
String fileaddress;
private JButton btn_next_pane2;
static String filename;
static FolderInfo folderInfo;
static String[] si;
static String foldername;
static String fname;
JPanel panel_1;
JPanel panel_2;
JPanel panel_3;
JPanel panel_4;
static File[] files;
String msg;
static JTree tree;
static DefaultTreeModel model;
static DefaultMutableTreeNode root;
static DefaultTableModel mode;
static DefaultMutableTreeNode lastNode;
ButtonGroup bgfiletype;
ButtonGroup bgnoOffile;
static JProgressBar progressBar_pane2;
private static JTable table;
static JTextField tf_Destination_Location;

private JPanel Cardlayout;


private JTable table_fileConvertion_panel4;
private static JTable table_mfilechooser;

public static void main(String[] args) {


EventQueue.invokeLater(new Runnable() {
public void run() {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Main_Frame frame = new Main_Frame();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

frame.setResizable(false);

} catch (Exception e) {

e.printStackTrace();
}

);

public Main_Frame() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 683, 571);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

table = new JTable();

Cardlayout = new JPanel();


Cardlayout.setBounds(0, 58, 667, 451);
contentPane.add(Cardlayout);
Cardlayout.setLayout(new CardLayout(0, 0));

panel_1 = new JPanel();


Cardlayout.add(panel_1, "panel_1");
panel_1.setLayout(null);

rdbtn_input_Mbox = new JRadioButton("Mbox");


rdbtn_input_Mbox.setBounds(6, 137, 51, 23);
panel_1.add(rdbtn_input_Mbox);

rdbtn_input_pst = new JRadioButton("Microsoft Outlook (.pst)");


rdbtn_input_pst.setBounds(6, 50, 139, 23);
panel_1.add(rdbtn_input_pst);

rdbtn_input_edb = new JRadioButton("Microsoft Exchange Software


(.edb)");
rdbtn_input_edb.setBounds(6, 97, 199, 23);
panel_1.add(rdbtn_input_edb);

rdbtn_input_ost = new JRadioButton("Exchange Offline Storage (.ost)");


rdbtn_input_ost.setBounds(6, 7, 179, 23);
panel_1.add(rdbtn_input_ost);

tf_FileChooser = new JTextField();


tf_FileChooser.setBounds(10, 364, 539, 23);
panel_1.add(tf_FileChooser);
tf_FileChooser.setColumns(10);

JButton btn_Browser_pane1 = new JButton("Browser");


btn_Browser_pane1.setBounds(559, 364, 89, 23);
panel_1.add(btn_Browser_pane1);

rdbtn_SingleFile = new JRadioButton("Single File");


rdbtn_SingleFile.setBounds(79, 320, 122, 23);
panel_1.add(rdbtn_SingleFile);

rdbtn_MultipleFile = new JRadioButton("Multiple File");


rdbtn_MultipleFile.setBounds(213, 320, 154, 23);
panel_1.add(rdbtn_MultipleFile);

JButton btn_next_pane1 = new JButton("Next >");


btn_next_pane1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

if ((rdbtn_input_ost.isSelected()) ||
(rdbtn_input_pst.isSelected())) {
try {
readAnOST_PstFile();
CardLayout card = (CardLayout)
Cardlayout.getLayout();
card.show(Cardlayout, "panel_2");
} catch (Exception e1) {

}
}
if (rdbtn_input_Mbox.isSelected()) {
CardLayout card = (CardLayout)
Cardlayout.getLayout();
card.show(Cardlayout, "panel_3");
}

}
});
btn_next_pane1.setBounds(555, 405, 89, 23);
panel_1.add(btn_next_pane1);

JScrollPane scrollPane_1 = new JScrollPane();


scrollPane_1.setBounds(283, 11, 374, 278);
panel_1.add(scrollPane_1);

table_mfilechooser = new JTable();


scrollPane_1.setViewportView(table_mfilechooser);

JComboBox comboBox_FiletypeChooser = new JComboBox();


comboBox_FiletypeChooser.setBounds(10, 190, 195, 20);
panel_1.add(comboBox_FiletypeChooser);

btn_Browser_pane1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

if ((rdbtn_input_ost.isSelected()) &&
(rdbtn_SingleFile.isSelected())) {

filterOSt();

singleFile();

if ((rdbtn_input_ost.isSelected()) &&
(rdbtn_MultipleFile.isSelected())) {

filterOSt();

multipleFile();
}

if ((rdbtn_input_Mbox.isSelected()) &&
(rdbtn_MultipleFile.isSelected())) {

filterMBOx();

multipleFile();

if ((rdbtn_input_Mbox.isSelected()) &&
(rdbtn_SingleFile.isSelected())) {

filterMBOx();

singleFile();
}

if ((rdbtn_input_pst.isSelected()) &&
(rdbtn_SingleFile.isSelected())) {

filterPst();

singleFile();

if ((rdbtn_input_pst.isSelected()) &&
(rdbtn_MultipleFile.isSelected())) {
filterPst();

multipleFile();

if ((rdbtn_input_edb.isSelected()) &&
(rdbtn_MultipleFile.isSelected())) {

filterEdb();

multipleFile();

if ((rdbtn_input_edb.isSelected()) &&
(rdbtn_SingleFile.isSelected())) {

filterEdb();

singleFile();

});

panel_2 = new JPanel();


Cardlayout.add(panel_2, "panel_2");
panel_2.setLayout(null);

btn_next_pane2 = new JButton("Next >");


btn_next_pane2.setBounds(570, 389, 87, 23);
panel_2.add(btn_next_pane2);

progressBar_pane2 = new JProgressBar();


progressBar_pane2.setBounds(467, 423, 190, 17);
panel_2.add(progressBar_pane2);

progressBar_pane2.setValue(0);

progressBar_pane2.setStringPainted(true);

JScrollPane scrollPane_forTable = new JScrollPane();


scrollPane_forTable.setBounds(157, 11, 500, 365);
panel_2.add(scrollPane_forTable);

table = new JTable();

table.setBackground(Color.WHITE);

table.setModel(new DefaultTableModel(new Object[][] {},

new String[] { "From", "Subject", "Recived Date" }));

table.getColumnModel().getColumn(0).setPreferredWidth(22);

scrollPane_forTable.setViewportView(table);
JButton btn_Previous_pane2 = new JButton("< Previous");
btn_Previous_pane2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout card = (CardLayout) Cardlayout.getLayout();
card.show(Cardlayout, "panel_1");
}
});
btn_Previous_pane2.setBounds(364, 387, 89, 23);
panel_2.add(btn_Previous_pane2);

JButton btn_Cancel_pane2 = new JButton("Cancel");


btn_Cancel_pane2.setBounds(471, 389, 89, 23);
panel_2.add(btn_Cancel_pane2);

JScrollPane scrollPane = new JScrollPane();


scrollPane.setBounds(10, 11, 135, 365);
panel_2.add(scrollPane);

tree = new JTree();


scrollPane.setViewportView(tree);

tree.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent arg0) {

TreePath tp = tree.getSelectionPath();

DefaultMutableTreeNode node = (DefaultMutableTreeNode)


tp.getLastPathComponent();

foldername = node.getUserObject().toString();

DefaultTableModel model = (DefaultTableModel)


table.getModel();

while (model.getRowCount() > 0) {

for (int i = 0; i < model.getRowCount(); ++i) {

model.removeRow(i);
}
}
try {
fileInhformation_Ost_Pst();
} catch (Exception e) {

}
}
});

tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("root


folder") {
{
}
}));

progressBar_pane2.setVisible(true);
btn_next_pane2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {


CardLayout card = (CardLayout) Cardlayout.getLayout();
card.show(Cardlayout, "panel_3");
}
});

panel_3 = new JPanel();


Cardlayout.add(panel_3, "panel_3");
panel_3.setLayout(null);

JButton btn_converter = new JButton("Convert");


btn_converter.setBounds(543, 417, 89, 23);
panel_3.add(btn_converter);

JButton btn_Designation = new JButton("Designation");


btn_Designation.setBounds(543, 374, 89, 23);
panel_3.add(btn_Designation);

tf_Destination_Location = new JTextField();


tf_Destination_Location.setBounds(10, 375, 518, 20);
panel_3.add(tf_Destination_Location);

tf_Destination_Location.setColumns(10);

JButton btn_previous_p3 = new JButton("< Previous");


btn_previous_p3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
CardLayout card = (CardLayout) Cardlayout.getLayout();
card.show(Cardlayout, "panel_2");
}
});
btn_previous_p3.setBounds(444, 417, 89, 23);
panel_3.add(btn_previous_p3);

JPanel panel_TaskFilter = new JPanel();


panel_TaskFilter
.setBorder(new TitledBorder(null, "Task Filter",
TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_TaskFilter.setBounds(66, 280, 512, 83);
panel_3.add(panel_TaskFilter);
panel_TaskFilter.setLayout(null);

JDateChooser dateChooser_Calender_FromDate = new JDateChooser();


dateChooser_Calender_FromDate.setBounds(10, 52, 114, 20);
panel_TaskFilter.add(dateChooser_Calender_FromDate);

JDateChooser dateChooser_calender_tilldate = new JDateChooser();


dateChooser_calender_tilldate.setBounds(211, 52, 114, 20);
panel_TaskFilter.add(dateChooser_calender_tilldate);

JLabel lbl_startdate = new JLabel("Start Date");


lbl_startdate.setBounds(10, 22, 114, 20);
panel_TaskFilter.add(lbl_startdate);

JLabel lbl_enddate = new JLabel("End Date\r\n");


lbl_enddate.setBounds(214, 24, 90, 17);
panel_TaskFilter.add(lbl_enddate);
JPanel panel_Calendeafilter = new JPanel();
panel_Calendeafilter.setBorder(
new TitledBorder(null, "Calendar Filter",
TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_Calendeafilter.setLayout(null);
panel_Calendeafilter.setBounds(66, 187, 512, 67);
panel_3.add(panel_Calendeafilter);

JLabel label = new JLabel("Start Date");


label.setBounds(10, 21, 114, 20);
panel_Calendeafilter.add(label);

JLabel label_2 = new JLabel("End Date\r\n");


label_2.setBounds(208, 23, 90, 17);
panel_Calendeafilter.add(label_2);

JDateChooser dateChooser = new JDateChooser();


dateChooser.setBounds(10, 42, 114, 20);
panel_Calendeafilter.add(dateChooser);

JDateChooser dateChooser_1 = new JDateChooser();


dateChooser_1.setBounds(208, 42, 114, 20);
panel_Calendeafilter.add(dateChooser_1);

JPanel panel_mailfilter = new JPanel();


panel_mailfilter.setLayout(null);
panel_mailfilter.setBorder(new
TitledBorder(UIManager.getBorder("TitledBorder.border"), "Mail Filter",
TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0,
0, 0)));
panel_mailfilter.setBounds(66, 79, 512, 83);
panel_3.add(panel_mailfilter);

JLabel label_1 = new JLabel("Start Date");


label_1.setBounds(10, 21, 114, 20);
panel_mailfilter.add(label_1);

JLabel label_3 = new JLabel("End Date\r\n");


label_3.setBounds(208, 23, 90, 17);
panel_mailfilter.add(label_3);

JComboBox comboBox_fileFilter = new JComboBox(new String[] {"Recived


DATE", "Delivered Date"});
comboBox_fileFilter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == comboBox_fileDestination_type) {
JComboBox ct = (JComboBox) e.getSource();
date = (String) ct.getSelectedItem();
}
}
});
comboBox_fileFilter.setBounds(399, 52, 89, 20);
panel_mailfilter.add(comboBox_fileFilter);

dateChooser_mail_fromdate = new JDateChooser();


dateChooser_mail_fromdate.setBounds(10, 52, 114, 20);
panel_mailfilter.add(dateChooser_mail_fromdate);
dateChooser_mail_tilldate = new JDateChooser();
dateChooser_mail_tilldate.setBounds(208, 52, 102, 20);
panel_mailfilter.add(dateChooser_mail_tilldate);

JLabel lblFilterDateBy = new JLabel("Filter Date by");


lblFilterDateBy.setBounds(399, 21, 65, 14);
panel_mailfilter.add(lblFilterDateBy);

comboBox_fileDestination_type = new JComboBox(new String[] { "PST",


"OST", "EML", "MSG", "EMLX", "HTML", "MHTML", "PDF" });
comboBox_fileDestination_type.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

if (e.getSource() == comboBox_fileDestination_type) {
JComboBox cb = (JComboBox) e.getSource();
msg = (String) cb.getSelectedItem();
}
}
});
comboBox_fileDestination_type.setBounds(262, 26, 116, 20);
comboBox_fileDestination_type.setSelectedIndex(0);
panel_3.add(comboBox_fileDestination_type);

dateChooser_mail_tilldate.getCalendarButton().addActionListener(new
ActionListener() {

public void actionPerformed(ActionEvent arg0) {

}
});
dateChooser_Calender_FromDate.getCalendarButton().addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});

panel_4 = new JPanel();


Cardlayout.add(panel_4, "panel_4");
panel_4.setLayout(null);

JScrollPane scrollPane_table_panel4 = new JScrollPane();


scrollPane_table_panel4.setBounds(10, 11, 647, 338);
panel_4.add(scrollPane_table_panel4);

table_fileConvertion_panel4 = new JTable();


scrollPane_table_panel4.setViewportView(table_fileConvertion_panel4);

JProgressBar progressBar_fileconvertion_panel4 = new JProgressBar();


progressBar_fileconvertion_panel4.setBounds(22, 380, 623, 26);
panel_4.add(progressBar_fileconvertion_panel4);

JButton btn_cancel_panel4 = new JButton("Cancel\r\n");


btn_cancel_panel4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btn_cancel_panel4.setBounds(276, 417, 89, 23);
panel_4.add(btn_cancel_panel4);
btn_Designation.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

destinationPath();

}
});

btn_converter.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

df = dateChooser_mail_fromdate.getDate();
da = dateChooser_mail_tilldate.getDate();

if (msg.equalsIgnoreCase("OST")) {

}
if (msg.equalsIgnoreCase("EML")) {
try {
ConvertMbox_eml();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (msg.equalsIgnoreCase("MSG")) {
ConvertMbox_msg();

}
if (msg.equalsIgnoreCase("html")) {
ConvertMbox_html();
}
if (msg.equalsIgnoreCase("pdf")) {

}
if (msg.equalsIgnoreCase("mhtml")) {

}
});

static void filterOSt() {

jFileChooser = new JFileChooser();

jFileChooser.setAcceptAllFileFilterUsed(false);

FileNameExtensionFilter filter = new


FileNameExtensionFilter(".OSTFile", "ost");

jFileChooser.addChoosableFileFilter(filter);
jFileChooser.showOpenDialog(null);

static void singleFile() {

File file = jFileChooser.getSelectedFile();

filename = file.getAbsolutePath();

String fnam = file.getName();

fname = fnam.replace(".mbx", " ");


new File(fname).mkdirs();
System.out.println(fname);
tf_FileChooser.setText(filename);

void destinationPath() {
if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File directory = jFileChooser.getCurrentDirectory();
destination_path = directory.getAbsolutePath();

tf_Destination_Location.setText(destination_path);
new File(destination_path+File.separator+fname).mkdir();
}
}

static void multipleFile() {

jFileChooser.setMultiSelectionEnabled(true);
jFileChooser.showOpenDialog(null);
files = jFileChooser.getSelectedFiles();

for (int i = 0; i < files.length; i++) {


if (files[i].isFile()) {
DefaultTableModel model = (DefaultTableModel)
table_mfilechooser.getModel();
model.addRow(new Object[] { files[i].getAbsolutePath() });
}
}

static void filterMBOx() {

jFileChooser = new JFileChooser();

jFileChooser.setAcceptAllFileFilterUsed(false);

FileNameExtensionFilter filter = new FileNameExtensionFilter(".Mbox",


"mbx");

jFileChooser.addChoosableFileFilter(filter);

jFileChooser.showOpenDialog(null);
}

static void filterPst() {

jFileChooser = new JFileChooser();

jFileChooser.setAcceptAllFileFilterUsed(false);

FileNameExtensionFilter filter = new FileNameExtensionFilter(".Pst",


"pst");

jFileChooser.addChoosableFileFilter(filter);

jFileChooser.showOpenDialog(null);

static void filterEdb() {

jFileChooser = new JFileChooser();

jFileChooser.setAcceptAllFileFilterUsed(false);

FileNameExtensionFilter filter = new FileNameExtensionFilter(".Edb",


"edb");

jFileChooser.addChoosableFileFilter(filter);

jFileChooser.showOpenDialog(null);
}

public static void readAnOST_PstFile() throws Exception {

String strPSTFile = filename;

pst = PersonalStorage.fromFile(strPSTFile);

FolderInfoCollection folderInfoCollection =
pst.getRootFolder().getSubFolders();

model = (DefaultTreeModel) tree.getModel();

root = new DefaultMutableTreeNode(filename);

model.setRoot(root);

int size = folderInfoCollection.size();

for (int i = 0; i < folderInfoCollection.size(); i++) {

folderInfo = (FolderInfo) folderInfoCollection.get_Item(i);

getTree(folderInfo.getDisplayName());

int si = ((i + 1) * 100) / size;


progressBar_pane2.setValue(si);

public static void getTree(String folderName) {

DefaultMutableTreeNode node = null;

if (folderName.contains(File.separator)) {

String parts[] =
folderName.split(Matcher.quoteReplacement(File.separator));

DefaultMutableTreeNode par = new


DefaultMutableTreeNode(parts[parts.length - 2]);
{
DefaultMutableTreeNode child = new
DefaultMutableTreeNode(parts[parts.length - 1]);

search(root, par);

lastNode.add(child);
}
}

else {
node = new DefaultMutableTreeNode(folderName);

model.insertNodeInto(node, root, root.getChildCount());

lastNode = node;
}
}

public static void search(TreeNode rootNode, DefaultMutableTreeNode


searchNode) {

for (int i = 0; i < rootNode.getChildCount(); i++) {

if
(rootNode.getChildAt(i).toString().equals(searchNode.toString())) {

lastNode = (DefaultMutableTreeNode) rootNode.getChildAt(i);


}

else {

search((DefaultMutableTreeNode) rootNode.getChildAt(i),
searchNode);
}

public static void fileInhformation_Ost_Pst() {


FolderInfo folderInfo = pst.getRootFolder().getSubFolder(foldername);

MessageInfoCollection messageInfoCollection = folderInfo.getContents();

for (int i = 0; i < messageInfoCollection.size(); i++)

{
MessageInfo messageInfo = (MessageInfo)
messageInfoCollection.get_Item(i);

MapiMessage contact = (MapiMessage)


pst.extractMessage(messageInfo);

String from = contact.getSenderEmailAddress();

Date DeliveryTime = contact.getDeliveryTime();

String Subject = contact.getSubject();

MapiAttachmentCollection attachment = contact.getAttachments();

mode = (DefaultTableModel) table.getModel();

mode.addRow(new Object[] { from, Subject, DeliveryTime });

public static void ConvertMbox_pst() {


PersonalStorage storage = MailStorageConverter.mboxToPst(filename,

destination_path + File.separator + "output25.pst");

public static void ConvertMbox_eml() throws Exception {


FileStream stream = new FileStream(filename, FileMode.OpenOrCreate,
FileAccess.Read);

MboxrdStorageReader reader = new


MboxrdStorageReader(stream.toInputStream(), false);

MailMessage message = reader.readNextMessage();

new File(destination_path+File.separator+fname).mkdir();

int i = 0;

while (message != null) {

MailMessageSaveType mm = MailMessageSaveType.getEmlFormat();
String sub= message.getSubject();
String subname = getRidOfIllegalFileNameCharacters(sub);

String pathto=destination_path;
message.save(destination_path+File.separator+fname+File.separator+subname+".eml",Sa
veOptions.createSaveOptions(mm));

i++;
message = reader.readNextMessage();
}

reader.dispose();
stream.close();
}

public static void ConvertMbox_msg() {


FileStream stream = new FileStream(filename, FileMode.OpenOrCreate,
FileAccess.Read);

MboxrdStorageReader reader = new


MboxrdStorageReader(stream.toInputStream(), false);

// Start reading messages


MailMessage message = reader.readNextMessage();

int i = 0;
new File(destination_path+File.separator+fname).mkdir();
while (message != null) {
new File(fname).mkdir();
System.out.println("Subject: " + message.getSubject());
MailMessageSaveType mm =
MailMessageSaveType.getOutlookMessageFormat();
String sub = message.getSubject();
String subname = getRidOfIllegalFileNameCharacters(sub);
message.save(destination_path +
File.separator+fname+File.separator + subname + ".msg",
SaveOptions.createSaveOptions(mm));
i++;
message = reader.readNextMessage();
;
System.out.println("done");
}

reader.dispose();
stream.close();
}

public static void ConvertMbox_html() {


FileStream stream = new FileStream(filename, FileMode.OpenOrCreate,
FileAccess.Read);

MboxrdStorageReader reader = new


MboxrdStorageReader(stream.toInputStream(), false);

MailMessage message = reader.readNextMessage();

int i = 0;

while (message != null) {


String sub = message.getSubject();

String subname = getRidOfIllegalFileNameCharacters(sub);

MailMessageSaveType mm = MailMessageSaveType.getHtmlFormat();
new File(destination_path+ File.separator+ subname).mkdir();

message.save(destination_path + File.separator + subname


+File.separator +subname+ ".html", SaveOptions.createSaveOptions(mm));
i++;
message = reader.readNextMessage();
}

reader.dispose();
stream.close();
}

public static void ost_pst() {


PersonalStorage ost = PersonalStorage.fromFile(filename);

ost.saveAs(destination_path + File.separator + "File.pst",


FileFormat.Pst);
}

public static void pst_ost() {


PersonalStorage ost = PersonalStorage.fromFile(filename);

ost.saveAs(destination_path + File.separator + "File.ost",


FileFormat.Ost);
}

public static void pst_eml() {

PersonalStorage pst = PersonalStorage.fromFile(filename);

FolderInfo folderInfo =
pst.getPredefinedFolder(StandardIpmFolder.SentItems);

MessageInfoCollection coll = folderInfo.getContents();

for (int i = 0; i < coll.size(); i++)

MessageInfo msgInfo = (MessageInfo) coll.get(i);

MapiMessage mapi = pst.extractMessage(msgInfo);

mapi.save(destination_path + File.separator + i + ".eml",


EmlSaveOptions.getDefaultEml());

}
}

public static void ost_msg() {


PersonalStorage pst = PersonalStorage.fromFile(filename);
FolderInfo folderInfo = pst.getRootFolder();

String strRootFolderName = destination_path + "msg";


new File(strRootFolderName).mkdir();

extractMsgFiles(folderInfo, pst, strRootFolderName);

public static void pst_msg() {

PersonalStorage pst = PersonalStorage.fromFile(filename);

FolderInfo folderInfo = pst.getRootFolder();

String strRootFolderName = destination_path + File.separator + fname +


File.separator + ".msg";
new File(strRootFolderName).mkdir();

extractMsgFiles(folderInfo, pst, strRootFolderName);


}

private static void extractMsgFiles(FolderInfo folderInfo, PersonalStorage


pst, String strPSTFile) {

String folderName = strPSTFile + File.separator +


folderInfo.getDisplayName();
new File(folderName).mkdir();

MessageInfoCollection messageInfoCollection = folderInfo.getContents();


for (int i = 0; i < messageInfoCollection.size(); i++) {
MessageInfo messageInfo = (MessageInfo)
messageInfoCollection.get_Item(i);

MapiMessage message = pst.extractMessage(messageInfo);

String messageName = null;


if (message.getSubject() == null ||
message.getSubject().isEmpty() == true) {
messageName =
getRidOfIllegalFileNameCharacters(messageInfo.getEntryIdString());
} else {
messageName =
getRidOfIllegalFileNameCharacters(message.getSubject());
}

message.save(messageName + ".msg");
}

if (folderInfo.hasSubFolders() == true) {
for (int i = 0; i < folderInfo.getSubFolders().size(); i++) {
FolderInfo subfolderInfo = (FolderInfo)
folderInfo.getSubFolders().get_Item(i);
extractMsgFiles(subfolderInfo, pst, strPSTFile);
}
}
}

private static String getRidOfIllegalFileNameCharacters(String strName) {


String strLegalName = strName.replace(":", " ").replace("\\", "
").replace("?", " ").replace("/", " ")
.replace("|", " ").replace("*", " ").replace("<", "
").replace(">", " ").replace("\t", " ")
.replace("\"", " ");
if (strLegalName.length() >= 100) {
strLegalName = strLegalName.substring(0, 100);
}
return strLegalName;
}

You might also like