Операция за архивиране и възстановяване с IMAP
Aspose.Email за Java предоставя възможност за архивиране и възстановяване на съобщения. За това API‑то предоставя следните методи.
Тази статия демонстрира как да архивирате и възстановявате съобщения, използвайки ImapClient клас.
Архивиране на съобщения
За архивиране на съобщения, използвайте ImapClient.backup метод, както е демонстрирано в следния откъс от код.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "data/";
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.setHost("imap.gmail.com");
imapClient.setUsername("your.username@gmail.com");
imapClient.setPassword("your.password");
imapClient.setPort(993);
imapClient.setSecurityOptions(SecurityOptions.Auto);
ImapMailboxInfo mailboxInfo = imapClient.getMailboxInfo();
ImapFolderInfo info = imapClient.getFolderInfo(mailboxInfo.getInbox().getName());
ImapFolderInfoCollection infos = new ImapFolderInfoCollection();
infos.addItem(info);
imapClient.backup(infos, dataDir + "\\ImapBackup.pst", com.aspose.email.BackupSettings.to_BackupSettings(BackupOptions.Recursive));
Възстановяване на съобщения
За архивиране на съобщения, използвайте ImapClient.restore метод, както е демонстрирано в следния откъс от код.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "data/";
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.setHost("imap.gmail.com");
imapClient.setUsername("your.username@gmail.com");
imapClient.setPassword("your.password");
imapClient.setPort(993);
imapClient.setSecurityOptions(SecurityOptions.Auto);
ImapRestoreSettings settings = new ImapRestoreSettings();
settings.setRecursive(true);
PersonalStorage pst = PersonalStorage.fromFile(dataDir + "\\ImapBackup.pst");
imapClient.restore(pst, settings);
Операция за архивиране и възстановяване с IMAP с MultiConnection
Когато работите с голям брой съобщения, операцията по архивиране/възстановяване може да отнеме много време. За това API‑то предоставя поддръжка за множество връзки по време на операцията за архивиране и възстановяване. За да активирате MultiConnection режима, задайте ImapClient.UseMultiConnection свойство за MultiConnectionMode.Enable. Следните откъси от код демонстрират операции за архивиране и възстановяване с активиран MultiConnection режим.
Архивиране на съобщения с MultiConnection
Следните откъси от код демонстрират операция за архивиране с активиран MultiConnection режим.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "data/";
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.setHost("imap.gmail.com");
imapClient.setUsername("your.username@gmail.com");
imapClient.setPassword("your.password");
imapClient.setPort(993);
imapClient.setSecurityOptions(SecurityOptions.Auto);
imapClient.setUseMultiConnection(MultiConnectionMode.Enable);
ImapMailboxInfo mailboxInfo = imapClient.getMailboxInfo();
ImapFolderInfo info = imapClient.getFolderInfo(mailboxInfo.getInbox().getName());
ImapFolderInfoCollection infos = new ImapFolderInfoCollection();
infos.addItem(info);
imapClient.backup(infos, dataDir + "\\ImapBackup.pst", com.aspose.email.BackupSettings.to_BackupSettings(BackupOptions.Recursive));
Възстановяване на съобщения с MultiConnection
Следните откъси от код демонстрират операция за възстановяване с активиран MultiConnection режим.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "data/";
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.setHost("imap.gmail.com");
imapClient.setUsername("your.username@gmail.com");
imapClient.setPassword("your.password");
imapClient.setPort(993);
imapClient.setSecurityOptions(SecurityOptions.Auto);
imapClient.setUseMultiConnection(MultiConnectionMode.Enable);
ImapRestoreSettings settings = new ImapRestoreSettings();
settings.setRecursive(true);
PersonalStorage pst = PersonalStorage.fromFile(dataDir + "\\Outlook.pst");
imapClient.restore(pst, settings);