EXAMINE command is not read-only (again?)

View: New views
5 Messages — Rating Filter:   Alert me  

EXAMINE command is not read-only (again?)

by Shane Kerr-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

All,

[ Apologies if this was fixed or otherwise addressed already. ]


I'm using dbmail 2.2.10, and it looks like the EXAMINE command is
marking messages as read when I FETCH them. This looks like a bug that
was fixed ages ago:

http://osdir.com/ml/mail.imap.dbmail.devel/2004-10/msg00124.html

However I have tested the behavior and it is still working this way.


If you run the attached Python script, you will see that the status of
the e-mail is changed, even though the IMAP library is using "EXAMINE"
to connect to the mailbox. To do this, run:

$ python ExamineFail.py imap-host imap-user
Flags for added message:
Flags for added message: \Seen

As you can see, the first time the message has no flags, and the second
time the message has the \Seen flag set. As I understand the RFC, this
should not be allowed.

It uses SSL. If you don't have this enabled then you can change the call
from IMAP4_SSL to IMAP4.


Note that you can use BODY.PEEK[] rather than RFC822 when getting the
e-mails and then the flags are not updated. The problem is not all
programs do this, but rather expect that read-only access is in fact
read-only.

--
Shane

[ExamineFail.py]

import imaplib
import sys
import getpass
import random
import email.parser
import time

# log in using host/user/password specified on command line
if (len(sys.argv) < 3) or (len(sys.argv) > 4):
    sys.stderr.write('Syntax: %s host user [password]\n' % sys.argv[0])
    sys.exit(1)

host = sys.argv[1]
imap = imaplib.IMAP4_SSL(host)

user = sys.argv[2]
if len(sys.argv) == 4:
    password = sys.argv[3]
else:
    password = getpass.getpass("IMAP password for %s at %s:" % (user, host))
imap.login(user, password)

# create an e-mail message to put in the mailbox
message_text = """
From: nobody@...
To: nobody@...
Subject: ExamineFail.py message
Date: %s

This message is to show IMAP EXAMINE failing in dbmail.
""" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
parser = email.parser.Parser()
email_message = parser.parsestr(message_text.lstrip())
email_flags = ('\\Recent',)
email_time = imaplib.Time2Internaldate(time.time())

# create a new mailbox
created = False
while not created:
    mailbox_name = 'ExamineFail%05d' % random.randint(0, 99999)
    typ, replies = imap.create(mailbox_name)
    if typ == 'OK':
        created = True


# from this point on, execute in a try/except block so we can
# cleanup the mailbox on any errors
try:

    # put a message in the mailbox
    typ, replies = imap.append(mailbox_name,
                               email_flags, email_time, str(email_message))
    if typ != 'OK': raise RuntimeError('Unable to append to mailbox')

    # now select the mailbox for read-only access
    # this uses the EXAMINE command of IMAP
    typ, replies = imap.select(mailbox_name, True)
    if typ != 'OK': raise RuntimeError('Unable to select mailbox')

    # get our message
    typ, msgnum_info = imap.search(None, 'ALL')
    if typ != 'OK': raise RuntimeError('Unable to search')
    msgnums = msgnum_info[0].split()
    if len(msgnums) != 1:
       raise RuntimeError('%d messages in mailbox, should be 1' % len(msgnums))

    typ, data = imap.fetch(msgnums[0], '(RFC822 FLAGS)')
    if typ != 'OK': raise RuntimeError('Unable to fetch message')
    info = data[0]
    flags = imaplib.ParseFlags(info[0])
    msg = info[1]
    sys.stdout.write('Flags for added message: ' + ', '.join(flags) + '\n')

    # now open the mailbox again (still read-only), and check the flags
    typ, replies = imap.select(mailbox_name, True)
    if typ != 'OK': raise RuntimeError('Unable to select mailbox')
    typ, msgnum_info = imap.search(None, 'ALL')
    if typ != 'OK': raise RuntimeError('Unable to search')
    msgnums = msgnum_info[0].split()
    if len(msgnums) != 1:
       raise RuntimeError('%d messages in mailbox, should be 1' % len(msgnums))

    typ, data = imap.fetch(msgnums[0], '(RFC822 FLAGS)')
    if typ != 'OK': raise RuntimeError('Unable to fetch message')
    info = data[0]
    flags = imaplib.ParseFlags(info[0])
    msg = info[1]
    sys.stdout.write('Flags for added message: ' + ', '.join(flags) + '\n')

finally:
   typ, replies = imap.delete(mailbox_name)
   if typ != 'OK':
       sys.stderr.write('Error deleting mailbox "%s"\n' % mailbox_name)



_______________________________________________
DBmail mailing list
DBmail@...
http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail

Re: EXAMINE command is not read-only (again?)

by Paul J Stevens :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Shane Kerr wrote:

> All,
>
> [ Apologies if this was fixed or otherwise addressed already. ]
>
>
> I'm using dbmail 2.2.10, and it looks like the EXAMINE command is
> marking messages as read when I FETCH them. This looks like a bug that
> was fixed ages ago:
>
> http://osdir.com/ml/mail.imap.dbmail.devel/2004-10/msg00124.html

Bug confirmed for 2.2.11
But it's fixed in 2.3.6


--
  ________________________________________________________________
  Paul Stevens                                      paul at nfg.nl
  NET FACILITIES GROUP                     GPG/PGP: 1024D/11F8CD31
  The Netherlands________________________________http://www.nfg.nl
_______________________________________________
DBmail mailing list
DBmail@...
http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail

Re: EXAMINE command is not read-only (again?)

by Shane Kerr-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul,

On Wed, 2009-08-26 at 16:14 +0200, Paul J Stevens wrote:

> Shane Kerr wrote:
> > All,
> >
> > [ Apologies if this was fixed or otherwise addressed already. ]
> >
> >
> > I'm using dbmail 2.2.10, and it looks like the EXAMINE command is
> > marking messages as read when I FETCH them. This looks like a bug that
> > was fixed ages ago:
> >
> > http://osdir.com/ml/mail.imap.dbmail.devel/2004-10/msg00124.html
>
> Bug confirmed for 2.2.11
> But it's fixed in 2.3.6
Can you have a look at the attached patch against 2.2.11? I have no idea
if it is correct or not (I didn't even try to compile it), but it seems
like it might be more-or-less the right thing to do.

--
Shane

[dbmail-imapsession.c.patch]

--- dbmail-imapsession.c.org 2009-08-26 17:08:29.000000000 +0200
+++ dbmail-imapsession.c 2009-08-26 17:10:47.576625914 +0200
@@ -811,6 +811,7 @@
 static int _fetch_get_items(struct ImapSession *self, u64_t *uid)
 {
  int result;
+        int writeable;
  u64_t actual_cnt, tmpdumpsize;
  gchar *s = NULL;
 
@@ -958,8 +959,15 @@
  dbmail_imap_session_buff_append(self, "\r\n *BYE internal dbase error\r\n");
  return -1;
  }
+
+ /* also only adjust the seen flag if we can write to the mailbox */
+ writeable = acl_has_right(&ud->mailbox, ud->userid, ACL_RIGHT_WRITE);
+ if (writeable == -1) {
+ dbmail_imap_session_buff_append(self, "\r\n *BYE internal dbase error\r\n");
+ return -1;
+ }
 
- if (result == 1) {
+ if ((result == 1) && (writeable == 1)) {
  result = db_set_msgflag(self->msg_idnr, ud->mailbox.uid, setSeenSet, IMAPFA_ADD);
  if (result == -1) {
  dbmail_imap_session_buff_append(self, "\r\n* BYE internal dbase error\r\n");


_______________________________________________
DBmail mailing list
DBmail@...
http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail

2.2.x future was EXAMINE command is not read-only (again?)

by Jon Duggan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



> -----Original Message-----
> From: dbmail-bounces@... [mailto:dbmail-bounces@...] On
> Behalf Of Paul J Stevens
> Sent: 26 August 2009 15:14
> To: DBMail mailinglist
> Subject: Re: [Dbmail] EXAMINE command is not read-only (again?)
>
> Bug confirmed for 2.2.11
> But it's fixed in 2.3.6
>

Sounds ominous wrt 2.2.x

Some of us are stuck with large installations, which makes it less than trivial to even consider upgrading... I still remember the fun upgrading from 2.0, best part of 19hours doing alter tables etc.  

What's the plan for 2.2 maintenance/support/bugfixes, possibly even features - such as backporting any sieve enhancements?

Jon
_______________________________________________
DBmail mailing list
DBmail@...
http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail

Re: 2.2.x future was EXAMINE command is not read-only (again?)

by Paul J Stevens :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Duggan wrote:

> What's the plan for 2.2 maintenance/support/bugfixes, possibly even
> features - such as backporting any sieve enhancements?

If you really need support on 2.2, please consider contracting me.

http://www.dbmail.eu/solutions

--
   ________________________________________________________________
   Paul Stevens                                      paul at nfg.nl
   NET FACILITIES GROUP                     GPG/PGP: 1024D/11F8CD31
   The Netherlands________________________________http://www.nfg.nl
_______________________________________________
DBmail mailing list
DBmail@...
http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail