[imapfilter-devel] Error: attempt to index field 'INBOX'
David DeSimone
fox at verio.net
Sat Oct 20 07:55:16 EEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alejandro Jakubi <jakubi at df.uba.ar> wrote:
>
> > options.close = false
> > options.expunge = false
>
> I have found that with these options the messages moved to the folder
> SPAM with flag deleted are there when this folder is opened, but they
> are also there in the INBOX, marked deleted, ie. they are not moved
> but copied. But I do not want to keep copies in the INBOX. How do I
> do then?
This is the nature of IMAP.
The only way for imapfilter (or any IMAP client) to delete (remove) a
message from a folder, is to first mark the message deleted, and then
perform a CLOSE or EXPUNGE operation on the folder.
A "move" operation consists of:
1. Copy message to other folder
2. Mark first message deleted
3. CLOSE or EXPUNGE in order to remove message from original folder
If you disable the options.close and options.expunge flags, you
interrupt this behavior. Imapfilter marks the message as deleted,
expecting that it will be removed later, but it is not removed.
> Also, I want a log file whose lines are the actions (move, delete)
> that imapfilter makes, as those that I get on the output with the
> command line option -v:
>
> 4 messages moved from xxx/INBOX to xxx/mail/SPAM.
>
> plus the name of the rule/pattern used (or some equivalent label), and
> the date and time of the action. How do I get that?
Imapfilter uses LUA, which is a quite featureful language. Anything
that imapfilter can't do, you can write in LUA. If you don't like the
amount of information printed out by imapfilter -v, then have your
script functions print out information as they do it. Just "print" the
messages you'd like to see. If you don't know how to get information
such as the current date and time, you should go do some reading about
LUA, as this is really beyond the scope of imapfilter.
So, if imapfilter is not giving you the behavior you want, such as
moving and deleting messages properly, you just have to be a little more
clever about how you apply the flags you've been told about. Such as:
> function filtrar()
> r_spam = match(account1, 'INBOX', spam)
> account1.INBOX:mark_deleted(r_spam)
> move(account1, 'INBOX', account1, 'mail/SPAM', r_spam)
> ...
> end
This becomes:
function filtrar()
options.expunge = false -- Actually this is the default
r_spam = match(account1, 'INBOX', spam)
if (r_spam ~= nil and table.getn(r_spam) > 0)
then
print(table.getn(r_spam).." spam messages detected")
options.close = false
delete(account1, 'INBOX', r_spam)
options.close = true
copy(account1, 'INBOX', account1, 'mail/SPAM', r_spam)
end
-- [etc]
end
Since the "expunge" and "close" options are disabled, the delete()
method will mark the messages with the \Deleted flag, but they will not
not be removed.
Then, the "close" option is enabled, and the copy() method is used to
copy the messages to the SPAM folder. Since the messages were marked
with the \Deleted flag, that flag should get copied to the messages when
they reach the SPAM folder, and furthermore at the end of the copy() the
selected folder "INBOX" will be CLOSED, which causes the messages to be
removed.
It is possible that I am wrong, though, about the \Deleted flag being
copied to the other folder. I have not read the IMAP spec closely in
order to determine whether that flag is copied along with a message. If
it is not, then your task becomes a bit harder, because once the
messages are copied to their new folder, you cannot use the "r_spam"
result to set flags on the new messages. They have new ID numbers in
their new folder. You would have to perform another search on the SPAM
folder, to locate the messages and mark them with the \Deleted flag.
Happy scripting!
- --
David DeSimone == Network Admin == fox at verio.net
"This email message is intended for the use of the person to whom
it has been sent, and may contain information that is confidential
or legally protected. If you are not the intended recipient or have
received this message in error, you are not authorized to copy, dis-
tribute, or otherwise use this message or its attachments. Please
notify the sender immediately by return e-mail and permanently delete
this message and any attachments. Verio, Inc. makes no warranty that
this email is error or virus free. Thank you." --Lawyer Bot 6000
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFHGYo0FSrKRjX5eCoRApnQAJ41ZNHmVpfy2zmzP8MXMDwyBUPjmwCfRhaJ
mNpAcNjaiAQelIdtUTFv+Ek=
=Rvnu
-----END PGP SIGNATURE-----
More information about the Imapfilter-devel
mailing list