Skip to content

Commit 046a55d

Browse files
Merge pull request #3 from shoaibkhan-aspose/master
Aspose.Email Java Features missing in POI HSMF v1.2
2 parents 6c51884 + 9c1d600 commit 046a55d

File tree

20 files changed

+220
-17
lines changed

20 files changed

+220
-17
lines changed

Plugins/Aspose_Email_for_Apache_POI/.classpath

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
5-
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/Aspose/AsposeComponents/aspose-email-5.0.0-java/lib/aspose-email-5.0.0.0-jdk16.jar"/>
5+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/Aspose/AsposeComponents/aspose-email-5.7.0-java/lib/aspose-email-5.7.0.0-jdk16.jar"/>
66
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/poi-scratchpad-3.11-20141221.jar"/>
77
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/poi-3.11-20141221.jar"/>
8+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/Aspose/AsposeComponents/aspose-words-15.1.0-java/lib/aspose-words-15.1.0-jdk16.jar"/>
89
<classpathentry kind="output" path="bin"/>
910
</classpath>

Plugins/Aspose_Email_for_Apache_POI/src/asposefeatures/conversion/msgtootherformats/java/AsposeConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public static void main(String[] args)
1111
String dataPath = "src/asposefeatures/conversion/msgtootherformats/data/";
1212

1313
// Initialize and Load an existing MSG file by specifying the MessageFormat
14-
MailMessage msg = MailMessage.load(dataPath + "message.msg", MessageFormat.getMsg());
14+
MailMessage msg = MailMessage.load(dataPath + "message.msg");
1515

1616
// Save the Email message to disk by specifying the EML and MHT MailMessageSaveType
1717
msg.save(dataPath + "AsposeMessage.eml", MailMessageSaveType.getEmlFormat());
18-
msg.save(dataPath + "Asposemessage.mhtml", MailMessageSaveType.getMHtmlFromat());
18+
msg.save(dataPath + "Asposemessage.mhtml", MailMessageSaveType.getMHtmlFormat());
1919

2020
System.out.println("Done");
2121
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package asposefeatures.conversion.savemessageaspdf.java;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.FileInputStream;
6+
7+
import com.aspose.email.MailMessage;
8+
import com.aspose.email.SaveOptions;
9+
import com.aspose.words.Document;
10+
import com.aspose.words.LoadFormat;
11+
import com.aspose.words.LoadOptions;
12+
import com.aspose.words.SaveFormat;
13+
14+
public class SaveMessageAsPDF
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
String dataPath = "src/asposefeatures/conversion/savemessageaspdf/data/";
19+
20+
FileInputStream fstream = new FileInputStream(dataPath + "message.msg");
21+
MailMessage eml = MailMessage.load(fstream);
22+
23+
// Save the Message to output stream in MHTML format
24+
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
25+
eml.save(emlStream, SaveOptions.getDefaultMhtml());
26+
27+
// Load the stream in Word document
28+
LoadOptions lo = new LoadOptions();
29+
lo.setLoadFormat(LoadFormat.MHTML);
30+
Document doc = new Document(new ByteArrayInputStream(
31+
emlStream.toByteArray()), lo);
32+
33+
// Save to disc
34+
doc.save(dataPath + "About Aspose.Pdf", SaveFormat.PDF);
35+
36+
// or Save to stream
37+
ByteArrayOutputStream foStream = new ByteArrayOutputStream();
38+
doc.save(foStream, SaveFormat.PDF);
39+
40+
System.out.println("Done");
41+
}
42+
}

Plugins/Aspose_Email_for_Apache_POI/src/asposefeatures/programmingemail/addembeddedimagestoemail/java/EmbeddedImageInEmail.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public static void main(String[] args)
3434
LinkedResource res = new LinkedResource(dataPath + "Aspose.png", MediaTypeNames.Image.PNG);
3535
res.setContentId("companylogo");
3636

37-
// Add Linked resource to the messages Linked resource collection
37+
// Add Linked resource to the messages Linked resource collection
3838
message.getLinkedResources().addItem(res);
3939

4040
// Save message in EML, MSG and MHTML formats
4141
message.save(dataPath + "New.eml", MailMessageSaveType.getEmlFormat());
4242
message.save(dataPath + "New.msg", MailMessageSaveType.getOutlookMessageFormat());
43-
message.save(dataPath + "New.mhtml", MailMessageSaveType.getMHtmlFromat());
43+
message.save(dataPath + "New.mhtml", MailMessageSaveType.getMHtmlFormat());
4444

4545
System.out.println("Done.");
4646
}

Plugins/Aspose_Email_for_Apache_POI/src/asposefeatures/programmingemail/readembeddedattachments/java/ReadEmbeddedAttachments.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package asposefeatures.programmingemail.readembeddedattachments.java;
22

33
import com.aspose.email.Attachment;
4+
import com.aspose.email.LoadOptions;
45
import com.aspose.email.MailMessage;
6+
import com.aspose.email.MailMessageLoadOptions;
57
import com.aspose.email.MessageFormat;
68

79
public class ReadEmbeddedAttachments
@@ -14,7 +16,7 @@ public static void main(String[] args)
1416
{
1517
System.out.println("Reading message with embedded messages....");
1618

17-
MailMessage message = MailMessage.load(dataPath + "embedded.msg", MessageFormat.getMsg());
19+
MailMessage message = MailMessage.load(dataPath + "embedded.msg");
1820
ParseMessage(message);
1921

2022
System.out.println("Success");
@@ -52,7 +54,7 @@ private static void ParseMessage(MailMessage message)
5254
if ((attExt.equals(".eml")) || (att.getContentType().getMediaType().equals("text/plain") && att.getName().contains(".txt") == true && att.getName().contains("ATT") == true))
5355
{
5456
// Try to load this text file in MailMessage
55-
MailMessage attMsg = MailMessage.load(dataPath + attFileName + attExt, MessageFormat.getEml());
57+
MailMessage attMsg = MailMessage.load(dataPath + attFileName + attExt);
5658
// Call the function recursively to parse this message and attachments
5759
ParseMessage(attMsg);
5860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package asposefeatures.programmingemail.showhideextraprintheaders.java;
2+
3+
import com.aspose.email.MailMessage;
4+
import com.aspose.email.MhtFormatOptions;
5+
import com.aspose.email.MhtMessageFormatter;
6+
7+
public class ShowHideExtraPrintHeaders
8+
{
9+
public static void main(String[] args)
10+
{
11+
String dataPath = "src/asposefeatures/programmingemail/showhideextraprintheaders/data/";
12+
13+
String pageHeader = "<div><div class='pageHeader'>&quot;Panditharatne, Mithra&quot; &lt;[email protected]&gt;<hr/></div>";
14+
MailMessage message = MailMessage.load(dataPath + "message.eml");
15+
16+
MhtMessageFormatter mailFormatter = new MhtMessageFormatter();
17+
int options = MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.WriteCompleteEmailAddressToMht;
18+
19+
mailFormatter.format(message, options);
20+
21+
if(!message.getHtmlBody().contains(pageHeader))
22+
System.out.println("True");
23+
else
24+
System.out.println("False");
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package asposefeatures.workingwithappointments.addattachmentstocalenderitems.java;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.util.Calendar;
6+
import java.util.Date;
7+
import java.util.TimeZone;
8+
9+
import com.aspose.email.Appointment;
10+
import com.aspose.email.AppointmentSaveFormat;
11+
import com.aspose.email.Attachment;
12+
import com.aspose.email.MailAddress;
13+
import com.aspose.email.MailAddressCollection;
14+
import com.aspose.email.WeeklyRecurrencePattern;
15+
16+
public class AddAttachmentToCalenderItems
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
String dataPath = "src/asposefeatures/workingwithappointments/addattachmentstocalenderitems/data/";
21+
22+
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
23+
calendar.set(2012, Calendar.NOVEMBER, 1, 0, 0, 0);
24+
Date startDate = calendar.getTime();
25+
calendar.set(2012, Calendar.DECEMBER, 1);
26+
Date endDate = calendar.getTime();
27+
28+
MailAddressCollection attendees = new MailAddressCollection();
29+
attendees.addItem(new MailAddress("[email protected]", "Attendee"));
30+
WeeklyRecurrencePattern expected = new WeeklyRecurrencePattern(3);
31+
32+
Appointment app = new Appointment("Appointment Location", "Appointment Summary", "Appointment Description",
33+
startDate, endDate,
34+
new MailAddress("[email protected]", "Organizer"), attendees, expected);
35+
36+
//Attach a file from disc to this appointment
37+
File file = new File(dataPath + "AsposeXLS.xls");
38+
FileInputStream fis = new FileInputStream(file);
39+
40+
Attachment att = new Attachment(fis, file.getName());
41+
app.getAttachments().addItem(att);
42+
fis.close();
43+
44+
String savedFile = dataPath + "AppWithAttachments.ics";
45+
app.save(savedFile, AppointmentSaveFormat.Ics);
46+
47+
System.out.println("Done.");
48+
}
49+
}

0 commit comments

Comments
 (0)