perl imap将邮件移至垃圾桶(Mail :: IMAPClient) [英] perl imap move message to trash (Mail::IMAPClient)

查看:1734
本文介绍了perl imap将邮件移至垃圾桶(Mail :: IMAPClient)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有邮件从未看到移到垃圾桶(然后从收件箱中删除)。

I need to move all messages from unseen to the trash(and delete then from inbox).

my $inbox = $imap->select("Inbox");
my @mails = ( $imap->unseen );

foreach my $msgid (@mails) {
    $imap->set_flag( "Deleted", @mails )
        or die "Could not set flag: $@\n";
}

此代码完全删除邮件。 (没有删除)

This code delete messages completely. (without expunge too)

我试图使用move和copy:

I tried to use "move" and "copy":

my $Trash = "Trash";
my $newUid = $imap->move( $Trash, $msgid )
    or die "Could not move: $@\n";
my $uidList = $imap->copy( $Trash, @mails )
    or die "Could not copy: $@\n";

但是移动创建新的标记(文件夹)和复制不工作无法复制: 6否[TRYCREATE]没有文件夹垃圾桶(失败)
我试图使用名称:/垃圾桶,[imap]垃圾桶等,类似的结果。
这必须适用于不同的邮件服务!

But "move" create new mark(folder) and "copy" dont work "Could not copy: 6 NO [TRYCREATE] No folder Trash (Failure)" I tried to use name: /Trash, [imap]Trash etc., similar results. This must work for different mail services!

我使用 Mail :: IMAPClient

推荐答案

尝试以下代码,支持 RFC6154 像Gmail 。它应该检测垃圾文件夹的名称。

Try the code below for imap servers supporting RFC6154 like Gmail. It should detect Trash folder name.

use  Mail::IMAPClient; 
 ......
my $Trash;
{
  my @Trash;
  my @fhashes = $imap->folders_hash or die "Could not get list of folder hashes.\n";
  foreach my $fhash (@fhashes) {
    next unless map { /^\\Trash$/ ? ($_) : () } @{$fhash->{attrs}};
    push (@Trash, $fhash->{name});
  }
  $Trash = pop( @Trash) if @Trash == 1;
}
if( defined( $Trash)) {
   ...
}   

这篇关于perl imap将邮件移至垃圾桶(Mail :: IMAPClient)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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