使用IMAP传输完整数据(子文件夹)-PHP电子邮件迁移 [英] Transfer complete datas(subfolders) using IMAP - PHP Email migration

查看:174
本文介绍了使用IMAP传输完整数据(子文件夹)-PHP电子邮件迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将全部数据(所有子文件夹)从一台imap服务器传输到另一台imap服务器, 没有任何数据丢失.

I want to transfer Full amount of data(All subfolders) from one imap server to another , without any data loss.

推荐答案

如vpetersson所述,它与PHP部分不太匹配,因为可以使用任何imap客户端轻松地将电子邮件从一个Imap迁移到另一个Imap服务器.软件,例如,Microsoft Outlook,Mozilla Thunderbird,Apple Mail客户端等. 您如何做到这一点很简单. 如果您需要迁移的电子邮件帐户数量有限,这是Mozilla Thunderbird的示例工作流程,您也可以在其他任何客户端上执行相同的过程.

As vpetersson mentioned, it doesn't quite fit with the PHP part as migrating emails from one Imap to another Imap server can be done so easily with ANY imap client software as well, for examle, microsoft outlook, Mozilla Thunderbird, Apple Mail client and so on. How can you do it is simple. If the number of email accounts that you need to migrate are limited, here is the sample workflow for Mozilla Thunderbird and you can follow same process on any other client too.

  1. 创建一个新的Imap帐户,并将其命名为Source. [请确保您选择 IMAP作为协议,而非POP]
  2. 以可以连接到当前源Imap的方式对其进行配置 服务器,并取决于该帐户中电子邮件的数量 和您的网络速度,同步所有电子邮件可能需要一段时间.
  3. 同步完成后,为目标服务器创建一个新帐户, 命名为Target,并将其配置为IMAP.
  4. 目标帐户显然将为空,现在只需复制所有文件夹 从源帐户到目标帐户.
  5. Thunderbird将处理所有复制过程,并且还将上传 所有邮件自动发送到新服务器(默认行为) 对于IMAP帐户) 完成后,您将在两台服务器上拥有一个完整的电子邮件帐户克隆.
  1. Make a new Imap account, and name it Source. [make sure you select IMAP as protocol and NOT POP]
  2. Configure it in a way that it can connect to the current source Imap server and depending on the volume of your emails in that account and speed of your net, it may take a while to synch all emails.
  3. Once synch is complete, create a new account for the target server, name it let say Target and configure it as IMAP too.
  4. Target account will be empty obviously, now simply copy all folders from Source account to Target account.
  5. Thunderbird will handle all the copy process and also it will upload all mails to new server automatically(as its the default behavior for IMAP account) Once done you will have a complete clone of your email account on both servers.

或者,如果您必须使用PHP进行操作,则可能是因为您有数百个电子邮件帐户,并且使用上述方法不切实际,请按照以下步骤操作.

Alternately if you have to do it in PHP, maybe because you have hundreds of email accounts and going with the above mentioned method is not practical, then follow the below steps.

您也可以使用PHP_Imap库,但是如果您可以控制服务器,我建议您使用PEAR的Net_IMAP库,该库具有php statdard IMAP库中缺少的某些功能.

You can use PHP_Imap library too but if you have a control over your server, I will recommend using PEAR's Net_IMAP library, which has some features missing in php statdard IMAP library.

  1. 为您的所有帐户和每个帐户编写一个for循环
  2. 连接到服务器

  1. Write a for loop for all your accounts and for each account
  2. connect to the server

$ imapServer =新的Net_IMAP($ emailHost,143); $ loggedIn = $ imapServer-> login($ loginName,$ password); if($ loggedIn == true){ //代码在这里 }

$imapServer = new Net_IMAP($emailHost, 143); $loggedIn = $imapServer->login($loginName , $password); if($loggedIn == true){ //code goes here }

找到所有文件夹

$ mBoxes = $ imapServer-> getMailboxes('',0,true);

$mBoxes = $imapServer->getMailboxes('', 0, true);

每个文件夹

$ mBox = $ imapServer-> selectMailbox($ folderName);

$mBox = $imapServer->selectMailbox($folderName);

查找所有消息

$ msgsList = $ imapServer-> getMessagesList();

$msgsList = $imapServer->getMessagesList();

获取原始消息.

foreach($ msgUid){ $ fullRawMail = $ imapServer-> getMessages($ msgUid,false); }

foreach($msgUid){ $fullRawMail = $imapServer->getMessages($msgUid,false); }

连接到目标服务器

检查目标服务器是否与源服务器具有相同的文件夹,如果没有,则创建一个文件夹

check if target server has the same folder as source, if it doesn't then create a folder

将原始消息上载到目标服务器[特定文件夹].您可以为此使用php的imap_append函数.

upload raw message to target server [specific folder]. you can use php's imap_append function for that.

imap_append($ ImapStream,$ folderName,$ fullRawMail,"\ Seen");

imap_append($ImapStream, $folderName, $fullRawMail , "\Seen");

这篇关于使用IMAP传输完整数据(子文件夹)-PHP电子邮件迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆