简体   繁体   English

是否可以使用PHP的IMAP功能更改电子邮件?

[英]Is it possible to alter an email using PHP's IMAP functions?

I have no problem working with emails using PHP's IMAP functions, but I'd like to be able to alter messages physically and I'm just not sure it's possible. 使用PHP的IMAP函数处理电子邮件没有问题,但是我希望能够物理地更改消息 ,但不确定是否可以。 Has anyone had any success doing this? 有没有人成功做到这一点?

ie I'd like to be able to change the subject line, or I'd like to permanently remove signatures, or ads from the body, etc. 也就是说,我希望能够更改主题行,或者希望永久删除签名或广告从身上等。

So far the only way I can see is to: 到目前为止,我唯一能看到的方法是:

  1. load a message 加载一条消息
  2. gather up all of it's headers, etc. 收集所有的标题,等等。
  3. recreate the email using an email object of some sort and populate it with the old data 使用某种电子邮件对象重新创建电子邮件,并用旧数据填充
  4. Change the parts I want to change 更改我要更改的零件
  5. Delete the original message 删除原始消息
  6. Save the new message** 保存新消息**

** this is the only unknown here... do you know if it's possible to simply save a new message to a folder, or does it need to be received via SMTP? **这是这里唯一的未知...您知道是否可以将邮件简单地保存到文件夹,还是需要通过SMTP接收?

If I can simply save, do I need to worry about the message's order number (the unique id within the folder context, simple integer), or will the folder simply re-sort based on the messages indicated send date? 如果我可以简单地保存,是否需要担心邮件的订单号(文件夹上下文中的唯一ID,简单整数),还是仅根据显示的邮件发送日期对文件夹进行重新排序?

Any insights would be greatly appreciated! 任何见解将不胜感激!

As pointed out by @Max in the OP comments, the IMAP function I was looking for was 'APPEND' and the corresponding PHP method is http://php.net/manual/en/function.imap-append.php 正如@Max在OP注释中指出的那样,我正在寻找的IMAP函数是“ APPEND”,而对应的PHP方法是http://php.net/manual/en/function.imap-append.php

The syntax is: bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options = NULL [, string $internal_date = NULL ]] ) 语法为: bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options = NULL [, string $internal_date = NULL ]] )

There are examples in how to append a message to an IMAP folder in the reference page comments, but the basic example is as follows for adding a message to the 'INBOX.drafts' folder... 在参考页注释中有一些如何将消息添加到IMAP文件夹的示例,但是基本示例如下,用于将消息添加到“ INBOX.drafts”文件夹...

imap_append($stream, "{imap.example.org}INBOX.Drafts"
                   , "From: me@example.com\r\n"
                   . "To: you@example.com\r\n"
                   . "Subject: test\r\n"
                   . "\r\n"
                   . "this is a test message, please ignore\r\n"
                   );

... with $stream being the connection handle. ... $stream是连接句柄。 In my case I also want to include mime containers, which would be included in the concatenated $message , and would be appropriately encoded based on the content types. 在我的情况下,我还希望包含mime容器,该容器将包含在串联的$message ,并将根据内容类型进行适当编码。

Hope that helps! 希望有帮助!

The STORE command is not (IIRC) supported on the standard IMAP extension, but is available in the Hired IMAP client. 标准IMAP扩展不支持(IIRC)STORE命令,但是在Hired IMAP客户端中可用。 But I'm struggling to imagine why you would want to do this with IMAP in the first place - for most of the scenarios I can think of, it would make more sense to change the message on the sending MUA / MTA / MDA 但我很难想象您为什么要使用IMAP进行此操作-对于我能想到的大多数情况,在发送MUA / MTA / MDA上更改消息更有意义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM