Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Expunge" one message

42 views
Skip to first unread message

Chuck Anderson

unread,
Aug 2, 2013, 9:03:20 PM8/2/13
to
I pipe email that is coming into a mailbox to a Php script so I can
filter spam. If the spam test is positive my script (using Php imap
functions) moves the email from INBOX to a Junk folder. Recently I
decided to create a stricter filter that simply deletes the email (I
don't even want to know about these). The problem is that if I delete
that one email and then expunge the mailbox it will expunge all messages
that I may have marked for deletion using an email client that I might
be using at the same time. I do not want that to happen. I only want
to "remove" (delete and expunge) the one email that the Php filter
script is processing.

Is there a way to completely remove one message from a mailbox (leaving
other messages marked for deletion unpurged)?

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************

Sam

unread,
Aug 2, 2013, 10:32:16 PM8/2/13
to
Chuck Anderson writes:

> I pipe email that is coming into a mailbox to a Php script so I can filter
> spam. If the spam test is positive my script (using Php imap functions)
> moves the email from INBOX to a Junk folder. Recently I decided to create a
> stricter filter that simply deletes the email (I don't even want to know
> about these). The problem is that if I delete that one email and then
> expunge the mailbox it will expunge all messages that I may have marked for
> deletion using an email client that I might be using at the same time. I do
> not want that to happen. I only want to "remove" (delete and expunge) the
> one email that the Php filter script is processing.
>
> Is there a way to completely remove one message from a mailbox (leaving
> other messages marked for deletion unpurged)?

If the IMAP server implements the UIDPLUS extension, the server will support
an alternate EXPUNGE command that removes selected messages only. And, of
course, your IMAP library on the client side will have to support this
functioanlity as well.

If your IMAP server does not implement the UIDPLUS protocol extension, or
your IMAP library does not implement it, the UIDPLUS specification states
that you have no choice but remove the \Deleted flag from all existing
messages that should not be removed, do an EXPUNGE, then put them back.


Chuck Anderson

unread,
Aug 4, 2013, 2:02:56 AM8/4/13
to
Thanks (again) Sam. Glad you're listening in here. That last tip about
dealing with the Recent flag worked perfectly for me.

As far as I can tell Php IMAP does not handle UIDPLUS expunge, and I do
not even know about the server itself.

I think I am going to create a mail folder for messages I'd like to
erase, move them there, and then delete and expunge that folder. It
means opening another connection to the server for that folder and I've
read that this can use excess resources, but this is for a single
mailbox with low volume, and very few emails will need to be handled
this way. I was also hoping to keep it simpler, less code to debug and
maintain, but this will do.

Cheers

--
*****************************
Chuck Anderson � Boulder, CO

Sam

unread,
Aug 4, 2013, 9:41:14 AM8/4/13
to
Chuck Anderson writes:

> I think I am going to create a mail folder for messages I'd like to erase,
> move them there, and then delete and expunge that folder. It means opening
> another connection to the server for that folder and I've read that this can
> use excess resources, but this is for a single mailbox with low volume, and
> very few emails will need to be handled this way. I was also hoping to keep
> it simpler, less code to debug and maintain, but this will do.

That's going to open another can of worms. The ability to open the same
folder in multiple connections varies, with respect to being able to do it
all, depending on the server.

Chuck Anderson

unread,
Aug 5, 2013, 8:29:19 PM8/5/13
to
I am not sure exactly what you mean ("being able to do it all"). I have
always assumed that there can be multiple connections to a folder. E.g.,
using the IMAP mail client on my server and using a homespun IMAP client
on my home machine at the same time.

But regardless, my process is to forward email for an email account to
my Php script. It is already in the INBOX and now I can elect to move it
from there to a Spam folder. So, in this case I will merely forward it
to a new folder (Eraseme) that I will not even subscribe to in my IMAP
client - and use a cron job to delete and expunge that folder often.

I suppose could start over and not even use a mailbox, use a
forward-only email address piped to a script (STDIN) and then either
throw the message away or append it to a common mailbox.

In fact, once I have total faith in all of this I am probably going to
bypass the imap server altogether and save messages to a database where
I can manage my email however I wish.

Thanks again. I truly appreciate your assistance.

--
*****************************
Chuck Anderson • Boulder, CO

Sam

unread,
Aug 5, 2013, 9:37:13 PM8/5/13
to
Chuck Anderson writes:

> Sam wrote:
>> Chuck Anderson writes:
>>
>>> I think I am going to create a mail folder for messages I'd like to erase,
>>> move them there, and then delete and expunge that folder. It means opening
>>> another connection to the server for that folder and I've read that this can
>>> use excess resources, but this is for a single mailbox with low volume, and
>>> very few emails will need to be handled this way. I was also hoping to keep
>>> it simpler, less code to debug and maintain, but this will do.
>>
>> That's going to open another can of worms. The ability to open the same
>> folder in multiple connections varies, with respect to being able to do it
>> all, depending on the server.
>
> I am not sure exactly what you mean ("being able to do it all"). I have
> always assumed that there can be multiple connections to a folder. E.g.,
> using the IMAP mail client on my server and using a homespun IMAP client on
> my home machine at the same time.

There's no such requirement imposed by IMAP. IMAP servers are not required
to permit multiple access to the same account, or folder. Pretty much all
do, but this is not a requirement, and you will find occasional exceptions.

For example, the old UW-IMAP server is incapable of opening the same mbox
folder from multiple sessions, due to the inherent limitation of that
particular mail storage format.


0 new messages