Skip to content

Commit c2227f4

Browse files
committed
New Examples for Aspose.Email for Java 6.4.0 Release
1 parent 84011da commit c2227f4

File tree

9 files changed

+446
-0
lines changed

9 files changed

+446
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
import com.aspose.email.ImapClient;
11+
import com.aspose.email.ImapFolderInfo;
12+
import com.aspose.email.ImapMessageInfoCollection;
13+
import com.aspose.email.ImapPageInfo;
14+
import com.aspose.email.ImapQueryBuilder;
15+
16+
public class ListMessagesWithPagingSupport
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
//ExStart: ListMessagesWithPagingSupport
21+
ImapClient client = new ImapClient("server.domain.com", 587, "username", "password");
22+
client.setSecurityOptions(SecurityOptions.Auto);
23+
24+
try
25+
{
26+
try
27+
{
28+
int messagesNum = 12;
29+
int itemsPerPage = 5;
30+
31+
List<ImapPageInfo> pages = new List<ImapPageInfo>();
32+
ImapPageInfo pageInfo = client.listMessagesByPage(itemsPerPage);
33+
pages.addItem(pageInfo);
34+
while (!pageInfo.getLastPage())
35+
{
36+
pageInfo = client.listMessagesByPage(pageInfo.getNextPage());
37+
pages.addItem(pageInfo);
38+
}
39+
int retrievedItems = 0;
40+
for (ImapPageInfo folderCol : (Iterable<ImapPageInfo>) pages)
41+
retrievedItems += folderCol.getItems().size();
42+
}
43+
finally
44+
{
45+
}
46+
}
47+
finally { if (client != null)
48+
((IDisposable)client).dispose();
49+
}
50+
51+
// Display Status.
52+
System.out.println("Execution completed.");
53+
//ExEnd: ListMessagesWithPagingSupport
54+
}
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
import com.aspose.email.ImapClient;
11+
import com.aspose.email.ImapFolderInfo;
12+
import com.aspose.email.ImapMessageInfoCollection;
13+
import com.aspose.email.ImapPageInfo;
14+
import com.aspose.email.ImapQueryBuilder;
15+
16+
public class MoveMessageWithImapClient
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
//ExStart: MoveMessageWithImapClient
21+
ImapClient client = new ImapClient("host.domain.com", 587, "username", "password");
22+
client.setSecurityOptions(SecurityOptions.Auto);
23+
24+
try
25+
{
26+
String folderName = "EMAILNET-35151";
27+
if (!client.existFolder(folderName))
28+
client.createFolder(folderName);
29+
try
30+
{
31+
MailMessage message = new MailMessage(
32+
33+
34+
"EMAILNET-35151 - ",
35+
"EMAILNET-35151 ImapClient: Provide option to Move Message");
36+
client.selectFolder(ImapFolderInfo.IN_BOX);
37+
String uniqueId = client.appendMessage(ImapFolderInfo.IN_BOX, message);
38+
ImapMessageInfoCollection messageInfoCol1 = client.listMessages();
39+
client.moveMessage(uniqueId, folderName);
40+
client.commitDeletes();
41+
client.selectFolder(folderName);
42+
messageInfoCol1 = client.listMessages();
43+
client.selectFolder(ImapFolderInfo.IN_BOX);
44+
messageInfoCol1 = client.listMessages();
45+
}
46+
finally
47+
{
48+
try { client.deleteFolder(folderName); }
49+
catch(java.lang.RuntimeException e) { }
50+
}
51+
}
52+
finally { if (client != null)
53+
client.dispose();
54+
}
55+
56+
// Display Status.
57+
System.out.println("Execution completed.");
58+
//ExEnd: MoveMessageWithImapClient
59+
}
60+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
import com.aspose.email.ImapClient;
11+
import com.aspose.email.ImapFolderInfo;
12+
import com.aspose.email.ImapMessageInfoCollection;
13+
import com.aspose.email.ImapPageInfo;
14+
import com.aspose.email.ImapQueryBuilder;
15+
16+
public class SearchMessagesWithPagingSupport
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
//ExStart: SearchMessagesWithPagingSupport
21+
ImapClient client = new ImapClient("host.domain.com", 889, "username", "password");
22+
23+
client.setSecurityOptions(SecurityOptions.Auto);
24+
25+
int itemsPerPage = 5;
26+
String body = "2222222222222";
27+
ImapQueryBuilder iqb = new ImapQueryBuilder();
28+
iqb.getBody().contains(body);
29+
MailQuery query = iqb.getQuery();
30+
31+
client.selectFolder(ImapFolderInfo.IN_BOX);
32+
ImapMessageInfoCollection totalMessageInfoCol = client.listMessages(query);
33+
34+
List<ImapPageInfo> pages = new List<ImapPageInfo>();
35+
ImapPageInfo pageInfo = client.listMessagesByPage(ImapFolderInfo.IN_BOX, query, itemsPerPage);
36+
pages.add(pageInfo);
37+
while (!pageInfo.getLastPage())
38+
{
39+
pageInfo = client.listMessagesByPage(ImapFolderInfo.IN_BOX, query, pageInfo.getNextPage());
40+
pages.add(pageInfo);
41+
}
42+
int retrievedItems = 0;
43+
for (ImapPageInfo folderCol : (Iterable<ImapPageInfo>) pages)
44+
retrievedItems += folderCol.getItems().size();
45+
client.dispose();
46+
47+
// Display Status.
48+
System.out.println("Execution completed.");
49+
//ExEnd: SearchMessagesWithPagingSupport
50+
}
51+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
11+
12+
public class GetMarkersInformation
13+
{
14+
public static void main(String[] args) throws Exception
15+
{
16+
//ExStart: GetMarkersInformation
17+
FileInputStream stream = new FileInputStream("file");
18+
try
19+
{
20+
MboxrdStorageReader reader = new MboxrdStorageReader(stream, false);
21+
try
22+
{
23+
MailMessage msg;
24+
String[] fromMarker = { null };
25+
while ((msg = reader.readNextMessage(/*out*/fromMarker)) != null)
26+
{
27+
System.out.println(fromMarker[0]);
28+
29+
msg.dispose();
30+
}
31+
}
32+
finally {
33+
if (reader != null)
34+
reader.dispose();
35+
}
36+
}
37+
finally {
38+
if (stream != null)
39+
((IDisposable) stream).dispose();
40+
}
41+
42+
FileOutputStream writeStream = new FileOutputStream("file");
43+
try
44+
{
45+
MboxrdStorageWriter writer = new MboxrdStorageWriter(writeStream, false);
46+
try
47+
{
48+
MailMessage msg = MailMessage.load("msgFile");
49+
String[] fromMarker = { null };
50+
writer.writeMessage(msg, /*out*/fromMarker);
51+
System.out.println(fromMarker[0]);
52+
}
53+
finally {
54+
if (writer != null) ((IDisposable)writer).dispose(); }
55+
}
56+
finally {
57+
if (writeStream != null)
58+
((IDisposable)writeStream).dispose();
59+
}
60+
61+
62+
// Display Status.
63+
System.out.println("Execution completed.");
64+
//ExEnd: GetMarkersInformation
65+
}
66+
}

Examples/src/main/java/com/aspose/email/examples/email/CreateNewEmail.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class CreateNewEmail
1919
{
2020
public static void main(String[] args) throws Exception
2121
{
22+
//ExStart: CreateNewEmail
2223
// The path to the documents directory.
2324
String dataDir = Utils.getDataDir(CreateNewEmail.class);
2425

@@ -48,7 +49,19 @@ public static void main(String[] args) throws Exception
4849
message.save(dataDir + "Message.msg", SaveOptions.getDefaultMsg());
4950
message.save(dataDir + "Message.mhtml", SaveOptions.getDefaultMhtml());
5051

52+
//Save as OFT
53+
try
54+
{
55+
MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode();
56+
options.setSaveAsTemplate(true);
57+
message.save("emlToOft.oft", options);
58+
}
59+
finally { if (eml != null)
60+
((IDisposable)eml).dispose();
61+
}
62+
5163
// Display Status.
5264
System.out.println("New Emails created successfully.");
65+
//ExEnd: CreateNewEmail
5366
}
5467
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
11+
import com.aspose.email.Appointment;
12+
import com.aspose.email.AppointmentPageInfo;
13+
import com.aspose.email.EWSClient;
14+
import com.aspose.email.ExchangeDelegateFolderPermissionLevel;
15+
import com.aspose.email.ExchangeDelegateUser;
16+
import com.aspose.email.ExchangeFolderInfoCollection;
17+
import com.aspose.email.ExchangeFolderPageInfo;
18+
import com.aspose.email.ExchangeMessagePageInfo;
19+
20+
public class ListAppointmentsWithPagingSupport
21+
{
22+
public static void main(String[] args) throws Exception
23+
{
24+
//ExStart: ListAppointmentsWithPagingSupport
25+
final IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password");
26+
+
27+
try
28+
{
29+
try
30+
{
31+
int appNumber = 10;
32+
int itemsPerPage = 2;
33+
List<AppointmentPageInfo> pages = new List<AppointmentPageInfo>();
34+
AppointmentPageInfo pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage);
35+
pages.addItem(pagedAppointmentCol);
36+
while (!pagedAppointmentCol.getLastPage())
37+
{
38+
pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage, pagedAppointmentCol.getPageOffset() + 1);
39+
pages.addItem(pagedAppointmentCol);
40+
}
41+
int retrievedItems = 0;
42+
for (AppointmentPageInfo folderCol : (Iterable<AppointmentPageInfo>) pages)
43+
retrievedItems += folderCol.getItems().size();
44+
}
45+
finally
46+
{
47+
}
48+
}
49+
finally { if (client != null) ((IDisposable)client).dispose(); }
50+
51+
// Display Status.
52+
System.out.println("Execution completed.");
53+
//ExEnd: ListAppointmentsWithPagingSupport
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.exchange;
10+
11+
import com.aspose.email.Appointment;
12+
import com.aspose.email.AppointmentPageInfo;
13+
import com.aspose.email.EWSClient;
14+
import com.aspose.email.ExchangeDelegateFolderPermissionLevel;
15+
import com.aspose.email.ExchangeDelegateUser;
16+
import com.aspose.email.ExchangeFolderInfoCollection;
17+
import com.aspose.email.ExchangeFolderPageInfo;
18+
import com.aspose.email.ExchangeMessagePageInfo;
19+
20+
public class ListFoldersWithPagingSupport
21+
{
22+
public static void main(String[] args) throws Exception
23+
{
24+
//ExStart: ListFoldersWithPagingSupport
25+
final IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password");
26+
try
27+
{
28+
int itemsPerPage = 5;
29+
ExchangeFolderInfoCollection totalFoldersCollection = client.listSubFolders(client.getMailboxInfo().getRootUri());
30+
31+
//////////////////////////////////////////////////////
32+
33+
List<ExchangeFolderPageInfo> pages = new List<ExchangeFolderPageInfo>();
34+
ExchangeFolderPageInfo pagedFoldersCollection = client.listSubFoldersByPage(client.getMailboxInfo().getRootUri(), itemsPerPage);
35+
36+
pages.addItem(pagedFoldersCollection);
37+
while (!pagedFoldersCollection.getLastPage())
38+
{
39+
pagedFoldersCollection = client.listSubFoldersByPage(client.getMailboxInfo().getRootUri(), itemsPerPage, pagedFoldersCollection.getPageOffset() + 1);
40+
pages.addItem(pagedFoldersCollection);
41+
}
42+
int retrievedFolders = 0;
43+
for (ExchangeFolderPageInfo pageCol : (Iterable<ExchangeFolderPageInfo>) pages)
44+
retrievedFolders += pageCol.getItems().size();
45+
46+
}
47+
finally { if (client != null)
48+
((IDisposable)client).dispose();
49+
}
50+
51+
// Display Status.
52+
System.out.println("Execution completed.");
53+
//ExEnd: ListFoldersWithPagingSupport
54+
}
55+
}

0 commit comments

Comments
 (0)