Author Topic: Messages deleted by IMAP client on exchange server  (Read 6318 times)

crodgers

  • Newbie
  • *
  • Posts: 10
Messages deleted by IMAP client on exchange server
« on: April 27, 2016, 12:40:44 pm »
Hi,

I have an exchange email account which I access with AquaMail and by IMAP (with Thunderbird) from my computer.

When I delete or move a message with Thunderbird (IMAP on the computer) they get flagged as "deleted".

In the Windows Outlook client they appear with a red line crossing through the message.

But in AquaMail these messages appear like a normal "read" message.

They only disappear from AquaMail when I "compact folders" from the IMAP client (equivalent to an IMAP expunge command I think).

Is there a way to hide these deleted messages from view in AquaMail?

Thanks,

Chris.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Messages deleted by IMAP client on exchange server
« Reply #1 on: April 28, 2016, 11:08:56 pm »
They should be, AquaMail hides any messages with \Deleted from view completely.

Are you sure your account is set up as IMAP and not POP3 in AquaMail?

And it seems there is a way to make Thunderbird issue an EXPUNGE more often, automatically:

http://kb.mozillazine.org/Compacting_folders#Automatically
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

crodgers

  • Newbie
  • *
  • Posts: 10
Re: Messages deleted by IMAP client on exchange server
« Reply #2 on: April 29, 2016, 04:39:37 pm »
Hi,

Thanks for replying.

I use the exchange account type (so activesync protocol I gues?) on my phone because this gets me access to the global address list and my calendar.

But I am using Thunderbird IMAP on a PC at the same time.

I think that AquaSync is not picking up the Deleted property of the message when it syncs with ActiveSync to exchange.

Can this be fixed?

Best wishes,

Chris.

crodgers

  • Newbie
  • *
  • Posts: 10
Re: Messages deleted by IMAP client on exchange server
« Reply #3 on: April 29, 2016, 07:13:58 pm »
And after some further testing, I can also see there are issues with synchronising the "Replied" flags too.

If I reply to a message in Thunderbird (IMAP client to exchange server) then it is marked with the replied arrow on both Thunderbird AND on phone.

But I reply to a message on the phone (Exchange ActiveSync setup in AquaMail) then the phone shows a replied arrow BUT Thunderbird DOES NOT.

C.
« Last Edit: April 29, 2016, 07:23:31 pm by crodgers »

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Messages deleted by IMAP client on exchange server
« Reply #4 on: April 29, 2016, 07:23:29 pm »
Ah, so you're mixing different mail protocols.

\Deleted:

Exchange has no notion of IMAP's "\Deleted" flag (which means "deleted but not quite yet").

I suppose when Thunderbird sets \Deleted but does not EXPUNGE, the message is still reported by Exchange as "alive" and so it's there in AquaMail.

\Answered:

Exchange represents this is with "MAPI properties", and the way AquaMail does it does show in Office 365 web mail and Outlook.

So I suppose it's the opposite - your server does not map this flag from Exchange to IMAP.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

crodgers

  • Newbie
  • *
  • Posts: 10
Re: Messages deleted by IMAP client on exchange server
« Reply #5 on: April 29, 2016, 07:25:24 pm »
Thanks.

However, note that this DOES work between Outlook and Thunderbird, or Outlook Web Access and Thunderbird. So I think it is possible to fix if you may have the time...?

C.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Messages deleted by IMAP client on exchange server
« Reply #6 on: April 29, 2016, 07:28:42 pm »
For the \Deleted flag there is nothing to fix, if the server still reports messages with this flag set (over IMAP) as "alive" -- since Exchange has no concept of "deleted but no really" -- then those messages will be synced.

For the \Replied flag I've done this from MS documentation:

LastVerbExecuted property (0x1081, Integer) which contains values 102 for replied and 104 for forwared.

RawIcon property (0x1080, Integer) which is 261 for replied and 262 for forwarded.

If you have suggestions for a better way to do it, I'm listening.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

crodgers

  • Newbie
  • *
  • Posts: 10
Re: Messages deleted by IMAP client on exchange server
« Reply #7 on: April 29, 2016, 07:42:10 pm »
Thanks for the prompt replies. I'm afraid I know practically nothing about ActiveSync. A quick Google reveals this is a known issue for other devices.

E.g. http://support.blackberry.com/kb/articleDetail?ArticleNumber=000034259 [nofollow]
or e.g. http://forums.crackberry.com/blackberry-10-os-f269/emails-replied-bb-does-not-indicate-outlook-exchange-788808/ [nofollow] (long long thread though)

Is what you do roughly equivalent to this in the Android code
http://omapzoom.org/?p=platform/packages/apps/Exchange.git;a=blob;f=src/com/android/exchange/adapter/EmailSyncParser.java;hb=8b32d80125a962d5815acdec7cb3bd0c25e5d88b [nofollow]
around line 660.

656                 case Tags.EMAIL2_LAST_VERB_EXECUTED:
 657                     int val = getValueInt();
 658                     // Clear out the old replied/forward flags and add in the new flag
 659                     flags = oldFlags & ~(EmailContent.Message.FLAG_REPLIED_TO
 660                             | EmailContent.Message.FLAG_FORWARDED);
 661                     if (val == LAST_VERB_REPLY || val == LAST_VERB_REPLY_ALL) {
 662                         // We aren't required to distinguish between reply and reply all here
 663                         flags |= EmailContent.Message.FLAG_REPLIED_TO;
 664                     } else if (val == LAST_VERB_FORWARD) {
 665                         flags |= EmailContent.Message.FLAG_FORWARDED;
 666                     }
 667                     break;
 668                 default:
 669                     skipTag();
 670             }
 671         }
 672         // See if there are flag changes re: read, flag (favorite) or replied/forwarded
 673         if (((read != null) && !oldRead.equals(read)) ||
 674                 ((flag != null) && !oldFlag.equals(flag)) || (flags != null)) {
 675             changes.add(new ServerChange(id, read, flag, flags));
 676         }


I'll let you know if I come across the solution.

crodgers

  • Newbie
  • *
  • Posts: 10
Re: Messages deleted by IMAP client on exchange server
« Reply #8 on: April 29, 2016, 07:44:44 pm »
One more thought before I go. I found this

Do you also set the LastVerbExecutionTime too?

From https://msdn.microsoft.com/en-us/library/office/dn617213(v=exchg.150).aspx [nofollow] near the bottom

public static void FindRecentlySent(EmailMessage messageToCheck)
{
    // Create extended property definitions for PidTagLastVerbExecuted and PidTagLastVerbExecutionTime.
    ExtendedPropertyDefinition PidTagLastVerbExecuted = new ExtendedPropertyDefinition(0x1081, MapiPropertyType.Integer);
    ExtendedPropertyDefinition PidTagLastVerbExecutionTime = new ExtendedPropertyDefinition(0x1082, MapiPropertyType.SystemTime);

    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, PidTagLastVerbExecutionTime, PidTagLastVerbExecuted);
    messageToCheck = EmailMessage.Bind(service, messageToCheck.Id, propSet);


    // Determine the last verb executed on the message and display output.
    object responseType;
    if (messageToCheck.TryGetProperty(PidTagLastVerbExecuted, out responseType))
    {
        object ReplyTime = null;
        switch (((Int32)responseType))
        {
            case 102: Console.WriteLine("A reply was sent to the '" + messageToCheck.Subject.ToString() + "' email message at");
                break;
            case 103: Console.WriteLine("A reply all was sent to the '" + messageToCheck.Subject.ToString() + "' email message at");
                break;
            case 104: Console.WriteLine("The '" + messageToCheck.Subject.ToString() + "' email message was forwarded at");
                break;
        }
        if (messageToCheck.TryGetProperty(PidTagLastVerbExecutionTime, out ReplyTime))
        {
            Console.WriteLine(((DateTime)ReplyTime).ToString() + ".");
        }
    }
    else
    {
        Console.WriteLine("No changes were made to  '" + messageToCheck.Subject.ToString() + "'.");
    }
}

mikeone

  • Hero Member
  • *****
  • Posts: 2762
Re: Messages deleted by IMAP client on exchange server
« Reply #9 on: April 29, 2016, 08:29:31 pm »
But I reply to a message on the phone (Exchange ActiveSync setup in AquaMail) then the phone shows a replied arrow BUT Thunderbird DOES NOT.
As far as I know, AquaMail does NOT support Exchange ActiveSync protocol, but does Exchange Web Services (EWS)
 8)

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Messages deleted by IMAP client on exchange server
« Reply #10 on: April 29, 2016, 09:36:44 pm »
My code already sets LastVerbExecutionTime, property 0x1082

It's like this:

      if ((flags & (MessageFlags.ANSWERED | MessageFlags.FORWARDED)) != 0) {
         EwsPropHelper.updateExtendedPropBegin(sb, EwsMessageCmd.BEGIN_RAW_ICON_PROP);
         if ((flags & MessageFlags.ANSWERED) != 0) {
            sb.append(EwsConstants.PR_ICON_INDEX_REPLIED);
         } else {
            sb.append(EwsConstants.PR_ICON_INDEX_FORWARDED);
         }
         EwsPropHelper.updateExtendedPropEnd(sb);

         EwsPropHelper.updateExtendedPropBegin(sb, EwsMessageCmd.BEGIN_RAW_LAST_VERB_EXECUTED_PROP);
         if ((flags & MessageFlags.ANSWERED) != 0) {
            sb.append(EwsConstants.EXCHIVERB_REPLYTOSENDER);
         } else {
            sb.append(EwsConstants.EXCHIVERB_FORWARD);
         }
         EwsPropHelper.updateExtendedPropEnd(sb);

         final long now = System.currentTimeMillis();

         EwsPropHelper.updateExtendedPropBegin(sb, EwsMessageCmd.BEGIN_RAW_LAST_VERB_TIME_PROP);
         EwsDateTime.append(sb, now);
         EwsPropHelper.updateExtendedPropEnd(sb);


where:

   public static final String BEGIN_RAW_LAST_VERB_EXECUTED_PROP =
   "PropertyTag=\"0x1081\" PropertyType=\"Integer\"";
   
   public static final String BEGIN_RAW_LAST_VERB_TIME_PROP =
   "PropertyTag=\"0x1082\" PropertyType=\"SystemTime\"";

   public static final int EXCHIVERB_REPLYTOSENDER = 102;
   public static final int EXCHIVERB_FORWARD = 104;


Re: Exchange ActiveSync protocol, but does Exchange Web Services

Makes no difference here. Both protocols are thin "mappings" of Exchange's view of the world.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Messages deleted by IMAP client on exchange server
« Reply #11 on: April 29, 2016, 09:40:13 pm »
Actual XML (just logged this after replying):

<UpdateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">
  <ItemChanges>
    <t:ItemChange>
      <t:ItemId Id="..." ChangeKey="..."/>
      <t:Updates>
        <t:SetItemField>
          <t:ExtendedFieldURI PropertyTag="0x1080" PropertyType="Integer"/>
          <t:Message>
            <t:ExtendedProperty>
              <t:ExtendedFieldURI PropertyTag="0x1080" PropertyType="Integer"/>
              <t:Value>261</t:Value>
            </t:ExtendedProperty>
          </t:Message>
        </t:SetItemField>
        <t:SetItemField>
          <t:ExtendedFieldURI PropertyTag="0x1081" PropertyType="Integer"/>
          <t:Message>
            <t:ExtendedProperty>
              <t:ExtendedFieldURI PropertyTag="0x1081" PropertyType="Integer"/>
              <t:Value>102</t:Value>
            </t:ExtendedProperty>
          </t:Message>
        </t:SetItemField>
        <t:SetItemField>
          <t:ExtendedFieldURI PropertyTag="0x1082" PropertyType="SystemTime"/>
          <t:Message>
            <t:ExtendedProperty>
              <t:ExtendedFieldURI PropertyTag="0x1082" PropertyType="SystemTime"/>
              <t:Value>2016-04-29T18:37:21Z</t:Value>
            </t:ExtendedProperty>
          </t:Message>
        </t:SetItemField>
      </t:Updates>
    </t:ItemChange>
  </ItemChanges>
</UpdateItem>
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/