我需要将所有未见的邮件移至垃圾箱(然后从收件箱中删除)。
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]没有文件夹垃圾箱(失败)”
我尝试使用名称:/Trash、[imap]Trash 等,结果类似。
这必须适用于不同的邮件服务!
i use Mail::IMAPClient https://metacpan.org/pod/Mail::IMAPClient
尝试使用下面的代码来获取支持的 imap 服务器RFC6154 https://www.rfc-editor.org/rfc/rfc6154 像 Gmail https://developers.google.com/gmail/imap_extensions。它应该检测垃圾文件夹名称。
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)) {
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)