unseen ); f-6ren">
gpt4 book ai didi

perl imap 将消息移至垃圾箱 (Mail::IMAPClient)

转载 作者:行者123 更新时间:2023-12-01 12:39:43 24 4
gpt4 key购买 nike

我需要将所有消息从看不见的移动到垃圾箱(然后从收件箱中删除)。

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";
}

此代码完全删除消息。 (也没有删除)

我尝试使用“移动”和“复制”:
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 NO [TRYCREATE] No folder Trash(Failure)”
我尝试使用名称:/Trash、[imap]Trash 等,结果类似。
这必须适用于不同的邮件服务!

我用 Mail::IMAPClient

最佳答案

对于支持 RFC6154 的 imap 服务器,请尝试使用以下代码like Gmail .它应该检测垃圾文件夹名称。

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),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26138604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com