Ejemplo n.º 1
0
        // Token: 0x06001760 RID: 5984 RVA: 0x0008AE90 File Offset: 0x00089090
        public static SyncStateUpgradeResult CheckAndUpgradeSyncStates(MailboxSession mailboxSession, DeviceIdentity deviceIdentity)
        {
            if (mailboxSession == null)
            {
                throw new ArgumentNullException("mailboxSession");
            }
            SafeHGlobalHandle   safeHGlobalHandle   = SafeHGlobalHandle.InvalidHandle;
            TiFolderSyncUpgrade tiFolderSyncUpgrade = new TiFolderSyncUpgrade();

            tiFolderSyncUpgrade.MailboxSession = mailboxSession;
            MailboxUtility           mailboxUtility           = new MailboxUtility();
            MailboxUtilityDeviceInfo mailboxUtilityDeviceInfo = null;
            MemoryStream             memoryStream             = null;

            try
            {
                mailboxUtility.MailboxSessionForUtility = mailboxSession;
                mailboxUtilityDeviceInfo = mailboxUtility.GetDevice(deviceIdentity);
                if (mailboxUtilityDeviceInfo == null)
                {
                    AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Failed to retrieve device info for: {0}", deviceIdentity);
                    return(SyncStateUpgradeResult.NoTiSyncState);
                }
                AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Starting sync state upgrade for device: {0}", deviceIdentity);
                safeHGlobalHandle = NativeMethods.AllocHGlobal(Marshal.SizeOf(typeof(FolderInfo)));
                StoreObjectId storeObjectId = null;
                storeObjectId = mailboxUtilityDeviceInfo.StoreObjectId;
                HashSet <string> folderList             = mailboxUtilityDeviceInfo.FolderList;
                FolderInfo       folderInfo             = default(FolderInfo);
                bool             containsFoldersyncFile = false;
                memoryStream = mailboxUtility.GetSyncState(storeObjectId, "FolderSyncFile");
                if (memoryStream != null)
                {
                    using (SafeHGlobalHandle safeHGlobalHandle2 = NativeMethods.AllocHGlobal((int)memoryStream.Length))
                    {
                        Marshal.Copy(memoryStream.GetBuffer(), 0, safeHGlobalHandle2.DangerousGetHandle(), (int)memoryStream.Length);
                        int num = SyncStateUpgrader.Foldersync_upgrade(safeHGlobalHandle2, (uint)memoryStream.Length, safeHGlobalHandle);
                        if (num != 0)
                        {
                            throw new AirSyncPermanentException(false);
                        }
                    }
                    folderInfo             = (FolderInfo)Marshal.PtrToStructure(safeHGlobalHandle.DangerousGetHandle(), typeof(FolderInfo));
                    containsFoldersyncFile = true;
                    MailboxUtility.ReclaimStream(memoryStream);
                    memoryStream = null;
                }
                Dictionary <string, StoreObjectType> dictionary2;
                Dictionary <string, StoreObjectId>   dictionary = SyncStateUpgrader.UpgradeFolderSyncHierarchySyncState(tiFolderSyncUpgrade, containsFoldersyncFile, folderInfo, deviceIdentity, out dictionary2);
                if (dictionary == null)
                {
                    mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true);
                }
                else
                {
                    SyncStateUpgradeHelper syncStateUpgradeHelper = new SyncStateUpgradeHelper(mailboxSession, tiFolderSyncUpgrade.SyncStateStorage);
                    foreach (string key in dictionary2.Keys)
                    {
                        StoreObjectType storeObjectType = dictionary2[key];
                        if (storeObjectType != StoreObjectType.Folder && storeObjectType != StoreObjectType.ContactsFolder && storeObjectType != StoreObjectType.CalendarFolder && storeObjectType != StoreObjectType.TasksFolder)
                        {
                            AirSyncDiagnostics.TraceDebug <StoreObjectType>(ExTraceGlobals.TiUpgradeTracer, null, "Removing unknown Ti folder of type {0}", storeObjectType);
                            dictionary.Remove(key);
                        }
                    }
                    if (!syncStateUpgradeHelper.UpgradeSyncState(dictionary, dictionary2, folderList, mailboxUtility, storeObjectId))
                    {
                        AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.TiUpgradeTracer, null, "Failed to upgrade folders for {0}", mailboxUtilityDeviceInfo.DisplayName);
                        mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true);
                        return(SyncStateUpgradeResult.UpgradeFailed);
                    }
                    tiFolderSyncUpgrade.UpdateLastFolderId(syncStateUpgradeHelper.MaxFolderSeen);
                }
                AirSyncDiagnostics.FaultInjectionTracer.TraceTest(3236310333U);
            }
            catch (Exception arg)
            {
                if (mailboxUtilityDeviceInfo != null)
                {
                    mailboxUtility.DeleteSyncStateStorage(new DeviceIdentity(mailboxUtilityDeviceInfo.DisplayName, mailboxUtilityDeviceInfo.ParentDisplayName, "AirSync"));
                }
                AirSyncDiagnostics.TraceDebug <DeviceIdentity, Exception>(ExTraceGlobals.TiUpgradeTracer, null, "Sync state upgrade failed for device: {0}\r\nException:\r\n{1}", deviceIdentity, arg);
                throw;
            }
            finally
            {
                if (memoryStream != null)
                {
                    MailboxUtility.ReclaimStream(memoryStream);
                    memoryStream = null;
                }
                if (mailboxUtilityDeviceInfo != null)
                {
                    mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true);
                }
                if (tiFolderSyncUpgrade != null)
                {
                    tiFolderSyncUpgrade.Close();
                    tiFolderSyncUpgrade = null;
                }
                safeHGlobalHandle.Close();
            }
            AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Finished sync state upgrade for device: {0}", deviceIdentity);
            return(SyncStateUpgradeResult.UpgradeComplete);
        }
Ejemplo n.º 2
0
        // Token: 0x06000FB5 RID: 4021 RVA: 0x00059390 File Offset: 0x00057590
        protected override void InternalCopyFrom(IProperty sourceProperty)
        {
            IContentProperty contentProperty = sourceProperty as IContentProperty;

            if (contentProperty == null)
            {
                throw new UnexpectedTypeException("IContentProperty", sourceProperty);
            }
            contentProperty.PreProcessProperty();
            try
            {
                long num = 0L;
                bool flag;
                long num3;
                if (BodyUtility.IsAskingForMIMEData(contentProperty, base.Options) && this.IsAcceptable(BodyType.Mime, out num, out flag))
                {
                    int num2 = -1;
                    this.bodyType = BodyType.Mime;
                    this.MIMEData = contentProperty.MIMEData;
                    if (base.Options.Contains("MIMETruncation"))
                    {
                        num2 = (int)base.Options["MIMETruncation"];
                    }
                    if (num2 >= 0 && (long)num2 < this.MIMEData.Length)
                    {
                        this.Truncated = true;
                        this.MIMESize  = (long)num2;
                    }
                    else
                    {
                        this.Truncated = false;
                        this.MIMESize  = this.MIMEData.Length;
                    }
                    num3 = contentProperty.MIMEData.Length;
                }
                else
                {
                    this.bodyType = contentProperty.GetNativeType();
                    if (this.bodyType == BodyType.None)
                    {
                        return;
                    }
                    num3 = contentProperty.Size;
                    foreach (BodyType bodyType in AirSyncContentProperty.GetPrioritizedBodyTypes(this.bodyType))
                    {
                        try
                        {
                            long num4;
                            if (this.ClientAccepts(contentProperty, bodyType, out num4, out num))
                            {
                                this.bodyType = bodyType;
                                num3          = num4;
                                break;
                            }
                        }
                        catch (ObjectNotFoundException arg)
                        {
                            AirSyncDiagnostics.TraceInfo <BodyType, ObjectNotFoundException>(ExTraceGlobals.AirSyncTracer, this, "ClientAccepts({0}) has thrown {1}", bodyType, arg);
                            num3          = 0L;
                            this.bodyType = BodyType.None;
                        }
                    }
                }
                if (contentProperty.IsIrmErrorMessage)
                {
                    this.Truncated = true;
                }
                base.XmlNode = base.XmlParentNode.OwnerDocument.CreateElement(base.AirSyncTagNames[0], base.Namespace);
                base.XmlParentNode.AppendChild(base.XmlNode);
                XmlNode xmlNode     = base.XmlNode;
                string  elementName = "Type";
                int     num5        = (int)this.bodyType;
                base.AppendChildNode(xmlNode, elementName, num5.ToString(CultureInfo.InvariantCulture));
                base.AppendChildNode(base.XmlNode, "EstimatedDataSize", num3.ToString(CultureInfo.InvariantCulture));
                if (this.Truncated)
                {
                    base.AppendChildNode(base.XmlNode, "Truncated", "1");
                }
                this.CopyData();
            }
            finally
            {
                contentProperty.PostProcessProperty();
            }
        }
        protected virtual Attachment12Data GetAttachmentData(Item message, Attachment attachment, string idbase, ref int index)
        {
            index++;
            Attachment14Data attachment14Data = new Attachment14Data();

            attachment14Data.Id = attachment.Id;
            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(message) && AirSyncUtility.IsProtectedVoicemailItem(message))
            {
                if (AttachmentHelper.IsProtectedVoiceAttachment(attachment.DisplayName))
                {
                    string valueOrDefault = message.GetValueOrDefault <string>(MessageItemSchema.RequireProtectedPlayOnPhone);
                    if (valueOrDefault != null && valueOrDefault.Equals("true", StringComparison.OrdinalIgnoreCase))
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Skip attachment requires protected play on phone");
                        return(null);
                    }
                    attachment14Data.DisplayName = AttachmentHelper.GetUnprotectedVoiceAttachmentName(attachment.DisplayName);
                }
                else
                {
                    if (AttachmentHelper.IsProtectedTranscriptAttachment(attachment.DisplayName))
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Skip protected transcript attachment");
                        return(null);
                    }
                    attachment14Data.DisplayName = attachment.DisplayName;
                }
            }
            else
            {
                attachment14Data.DisplayName = attachment.DisplayName;
            }
            if (string.IsNullOrEmpty(attachment14Data.DisplayName))
            {
                if (!string.IsNullOrEmpty(attachment.FileName))
                {
                    attachment14Data.DisplayName = attachment.FileName;
                    if (attachment.AttachmentType == AttachmentType.Ole && attachment.DisplayName.LastIndexOf('.') < 0)
                    {
                        Attachment14Data attachment14Data2 = attachment14Data;
                        attachment14Data2.DisplayName += ".jpg";
                    }
                }
                else if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
                {
                    using (Item itemAsReadOnly = ((ItemAttachment)attachment).GetItemAsReadOnly(null))
                    {
                        attachment14Data.DisplayName = (itemAsReadOnly.TryGetProperty(ItemSchema.Subject) as string);
                    }
                }
            }
            if (string.IsNullOrEmpty(attachment14Data.DisplayName))
            {
                attachment14Data.DisplayName = "????";
            }
            AirSyncDiagnostics.TraceDebug <int, string>(ExTraceGlobals.XsoTracer, this, "Attachment {0}, display name {1}", index, attachment14Data.DisplayName);
            attachment14Data.FileReference     = HttpUtility.UrlEncode(idbase + ":" + index);
            attachment14Data.Method            = Convert.ToByte((int)attachment.TryGetProperty(AttachmentSchema.AttachMethod));
            attachment14Data.EstimatedDataSize = attachment.Size;
            if (attachment.IsInline)
            {
                if (string.IsNullOrEmpty(attachment.ContentId))
                {
                    attachment14Data.ContentId = Guid.NewGuid().ToString();
                }
                else
                {
                    attachment14Data.ContentId = attachment.ContentId;
                }
            }
            if (attachment.ContentLocation != null)
            {
                attachment14Data.ContentLocation = attachment.ContentLocation.ToString();
            }
            if (!BodyConversionUtilities.IsMessageRestrictedAndDecoded(message))
            {
                attachment14Data.IsInline = attachment.IsInline;
            }
            return(attachment14Data);
        }
        public IEnumerator <Attachment12Data> GetEnumerator()
        {
            Item             message        = base.XsoItem as Item;
            Attachment12Data attachmentData = null;

            if (message == null)
            {
                throw new UnexpectedTypeException("Item", base.XsoItem);
            }
            MeetingRequest meetingRequest = base.XsoItem as MeetingRequest;

            if (meetingRequest == null || !meetingRequest.IsDelegated())
            {
                string idbase = null;
                if (this.idmapping != null)
                {
                    idbase = this.idmapping[MailboxSyncItemId.CreateForNewItem(message.Id.ObjectId)];
                }
                if (idbase == null)
                {
                    idbase = message.Id.ObjectId.ToBase64String();
                }
                if (message is MessageItem && ((MessageItem)message).IsRestricted && !BodyConversionUtilities.IsMessageRestrictedAndDecoded(message) && !BodyConversionUtilities.IsIRMFailedToDecode(message))
                {
                    object prop = message.TryGetProperty(MessageItemSchema.DRMLicense);
                    if (prop is byte[][])
                    {
                        byte[][] license = (byte[][])prop;
                        if (license.Length > 0)
                        {
                            attachmentData                   = new Attachment14Data();
                            attachmentData.DisplayName       = "message.rpmsg.license";
                            attachmentData.Method            = 1;
                            attachmentData.EstimatedDataSize = (long)license[0].Length;
                            attachmentData.IsInline          = false;
                            attachmentData.FileReference     = HttpUtility.UrlEncode(idbase + ":DRMLicense");
                            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Add DRM license as attachment, message is MessageItem {0}, message.IsRestricted {1}, IsDecoded {2}, FailedToDecode {3}", new object[]
                            {
                                message is MessageItem,
                                ((MessageItem)message).IsRestricted,
                                BodyConversionUtilities.IsMessageRestrictedAndDecoded(message),
                                BodyConversionUtilities.IsIRMFailedToDecode(message)
                            });
                            yield return(attachmentData);
                        }
                        else
                        {
                            AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.XsoTracer, this, "The license property on the DRM message is incorrect. Length = {0}", license.Length);
                        }
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "The license property on the DRM message is incorrect. prop = {0}", new object[]
                        {
                            prop
                        });
                    }
                }
                AttachmentCollection attachmentCollection = null;
                if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(message))
                {
                    attachmentCollection = ((RightsManagedMessageItem)message).ProtectedAttachmentCollection;
                }
                else
                {
                    if (BodyConversionUtilities.IsIRMFailedToDecode(message))
                    {
                        goto IL_3FC;
                    }
                    attachmentCollection = message.AttachmentCollection;
                }
                int index = -1;
                foreach (AttachmentHandle handle in attachmentCollection)
                {
                    using (Attachment attachment = attachmentCollection.Open(handle))
                    {
                        if (BodyUtility.IsClearSigned(message) && (string.Equals(attachment.FileName, "smime.p7m", StringComparison.OrdinalIgnoreCase) || string.Equals(attachment.ContentType, "multipart/signed", StringComparison.OrdinalIgnoreCase)))
                        {
                            continue;
                        }
                        attachmentData = this.GetAttachmentData(message, attachment, idbase, ref index);
                    }
                    if (attachmentData != null)
                    {
                        yield return(attachmentData);
                    }
                }
            }
IL_3FC:
            yield break;
        }
Ejemplo n.º 5
0
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            CalendarItem calendarItem = null;
            Task         task         = null;

            if (this.recurrenceType == TypeOfRecurrence.Calendar)
            {
                calendarItem = (base.XsoItem as CalendarItem);
                if (calendarItem == null)
                {
                    throw new UnexpectedTypeException("CalendarItem", base.XsoItem);
                }
                if (!calendarItem.IsOrganizer())
                {
                    AirSyncDiagnostics.TraceInfo(ExTraceGlobals.CommonTracer, null, "InternalCopyFromModified::Skip Recurrence change in case of attendee.");
                    return;
                }
            }
            else if (this.recurrenceType == TypeOfRecurrence.Task)
            {
                task = (base.XsoItem as Task);
                if (task == null)
                {
                    throw new UnexpectedTypeException("Task", base.XsoItem);
                }
            }
            INestedProperty nestedProperty = srcProperty as INestedProperty;

            if (nestedProperty == null)
            {
                throw new UnexpectedTypeException("INestedProperty", srcProperty);
            }
            RecurrenceData recurrenceData = nestedProperty.NestedData as RecurrenceData;

            if (recurrenceData == null)
            {
                throw new UnexpectedTypeException("RecurrenceData", nestedProperty.NestedData);
            }
            Recurrence        recurrence        = (this.recurrenceType == TypeOfRecurrence.Calendar) ? calendarItem.Recurrence : task.Recurrence;
            RecurrencePattern recurrencePattern = XsoRecurrenceProperty.CreateRecurrencePattern(this.recurrenceType, recurrenceData, recurrence);
            ExDateTime        startDate         = ExDateTime.MinValue;
            ExDateTime        endDate           = ExDateTime.MinValue;

            if (this.recurrenceType == TypeOfRecurrence.Calendar)
            {
                ExDateTime startTime          = calendarItem.StartTime;
                ExTimeZone exTimeZoneFromItem = TimeZoneHelper.GetExTimeZoneFromItem(calendarItem);
                startDate = exTimeZoneFromItem.ConvertDateTime(startTime);
                if (recurrenceData.HasUntil())
                {
                    ExDateTime until = recurrenceData.Until;
                    endDate = exTimeZoneFromItem.ConvertDateTime(until);
                }
            }
            else if (this.recurrenceType == TypeOfRecurrence.Task)
            {
                startDate = recurrenceData.Start;
                if (recurrenceData.HasUntil())
                {
                    endDate = recurrenceData.Until;
                }
            }
            RecurrenceRange range;

            try
            {
                if (recurrenceData.HasOccurences())
                {
                    range = new NumberedRecurrenceRange(startDate, (int)recurrenceData.Occurrences);
                }
                else if (recurrenceData.HasUntil())
                {
                    range = new EndDateRecurrenceRange(startDate, endDate);
                }
                else
                {
                    range = new NoEndRecurrenceRange(startDate);
                }
            }
            catch (ArgumentException ex)
            {
                throw new ConversionException(ex.Message);
            }
            bool ignoreCalendarTypeAndIsLeapMonth = recurrenceData.ProtocolVersion < 140;

            if (recurrence != null && recurrence.Pattern != null && recurrence.Pattern.Equals(recurrencePattern, ignoreCalendarTypeAndIsLeapMonth))
            {
                recurrencePattern = recurrence.Pattern;
            }
            try
            {
                if (this.recurrenceType == TypeOfRecurrence.Calendar)
                {
                    ExTimeZone exTimeZoneFromItem2 = TimeZoneHelper.GetExTimeZoneFromItem(calendarItem);
                    try
                    {
                        calendarItem.Recurrence = new Recurrence(recurrencePattern, range, exTimeZoneFromItem2, null);
                        goto IL_295;
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        if (recurrenceData.CalendarType == CalendarType.Default)
                        {
                            recurrenceData.CalendarType = CalendarType.Gregorian;
                            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.CommonTracer, null, "Replace calendar recurrence calendar type with Gregorian.");
                            recurrencePattern       = XsoRecurrenceProperty.CreateRecurrencePattern(this.recurrenceType, recurrenceData, recurrence);
                            calendarItem.Recurrence = new Recurrence(recurrencePattern, range, exTimeZoneFromItem2, null);
                            goto IL_295;
                        }
                        throw;
                    }
                }
                try
                {
                    task.Recurrence = new Recurrence(recurrencePattern, range);
                }
                catch (ArgumentOutOfRangeException)
                {
                    if (recurrenceData.CalendarType != CalendarType.Default)
                    {
                        throw;
                    }
                    recurrenceData.CalendarType = CalendarType.Gregorian;
                    AirSyncDiagnostics.TraceInfo(ExTraceGlobals.CommonTracer, null, "Replace task recurrence calendar type with Gregorian.");
                    recurrencePattern = XsoRecurrenceProperty.CreateRecurrencePattern(this.recurrenceType, recurrenceData, recurrence);
                    task.Recurrence   = new Recurrence(recurrencePattern, range);
                }
                task[TaskSchema.IsOneOff] = recurrenceData.DeadOccur;
                IL_295 :;
            }
            catch (NotSupportedException ex2)
            {
                throw new ConversionException(ex2.Message);
            }
        }
Ejemplo n.º 6
0
        private MessageItem CreateIrmErrorMessage()
        {
            RightsManagedMessageItem rightsManagedMessageItem = ((Item)base.XsoItem) as RightsManagedMessageItem;

            if (rightsManagedMessageItem == null)
            {
                return(null);
            }
            bool        flag        = false;
            MessageItem messageItem = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties);

            if (messageItem == null)
            {
                AirSyncDiagnostics.TraceError(ExTraceGlobals.XsoTracer, null, "Failed to create in memory message item");
                return(null);
            }
            try
            {
                Item.CopyItemContent(rightsManagedMessageItem, messageItem);
                using (TextWriter textWriter = messageItem.Body.OpenTextWriter(Microsoft.Exchange.Data.Storage.BodyFormat.TextPlain))
                {
                    RightsManagementFailureCode failureCode = rightsManagedMessageItem.DecryptionStatus.FailureCode;
                    if (failureCode > RightsManagementFailureCode.PreLicenseAcquisitionFailed)
                    {
                        switch (failureCode)
                        {
                        case RightsManagementFailureCode.FailedToExtractTargetUriFromMex:
                        case RightsManagementFailureCode.FailedToDownloadMexData:
                            textWriter.Write(Strings.IRMReachNotConfiguredBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                            goto IL_1F7;

                        case RightsManagementFailureCode.GetServerInfoFailed:
                            goto IL_1AF;

                        case RightsManagementFailureCode.InternalLicensingDisabled:
                        case RightsManagementFailureCode.ExternalLicensingDisabled:
                            break;

                        default:
                            switch (failureCode)
                            {
                            case RightsManagementFailureCode.ServerRightNotGranted:
                                textWriter.Write(Strings.IRMServerNotConfiguredBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                                goto IL_1F7;

                            case RightsManagementFailureCode.InvalidLicensee:
                                goto IL_149;

                            case RightsManagementFailureCode.FeatureDisabled:
                                break;

                            case RightsManagementFailureCode.NotSupported:
                            case RightsManagementFailureCode.MissingLicense:
                            case RightsManagementFailureCode.InvalidLicensingLocation:
                                goto IL_1AF;

                            case RightsManagementFailureCode.CorruptData:
                                textWriter.Write(Strings.IRMCorruptProtectedMessageBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                                goto IL_1F7;

                            case RightsManagementFailureCode.ExpiredLicense:
                                textWriter.Write(Strings.IRMLicenseExpiredBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                                goto IL_1F7;

                            default:
                                goto IL_1AF;
                            }
                            break;
                        }
                        flag = true;
                        goto IL_1F7;
                    }
                    if (failureCode == RightsManagementFailureCode.UserRightNotGranted)
                    {
                        textWriter.Write(Strings.IRMNoViewRightsBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                        goto IL_1F7;
                    }
                    if (failureCode != RightsManagementFailureCode.PreLicenseAcquisitionFailed)
                    {
                        goto IL_1AF;
                    }
IL_149:
                    textWriter.Write(Strings.IRMPreLicensingFailureBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                    goto IL_1F7;
IL_1AF:
                    AirSyncDiagnostics.TraceError <string>(ExTraceGlobals.XsoTracer, null, "IRM decryption status {0}", rightsManagedMessageItem.DecryptionStatus.FailureCode.ToString());
                    textWriter.Write(Strings.IRMServerNotAvailableBodyText.ToString(rightsManagedMessageItem.Session.PreferedCulture));
                    IL_1F7 :;
                }
            }
            catch (Exception)
            {
                if (messageItem != null)
                {
                    flag = true;
                }
                throw;
            }
            finally
            {
                if (flag)
                {
                    messageItem.Dispose();
                    messageItem = null;
                }
            }
            return(messageItem);
        }
Ejemplo n.º 7
0
 public ConversionException(int airSyncStatusCode, string message, Exception innerException) : base(new LocalizedString(message), innerException)
 {
     AirSyncDiagnostics.TraceWarning <int, string, string>(ExTraceGlobals.CommonTracer, this, "ConversionException has been thrown. ConversionStatusCode:'{0}', Message:'{1}', InnerException: '{2}'", airSyncStatusCode, (message != null) ? message : string.Empty, (innerException != null) ? innerException.Message : string.Empty);
     this.airSyncStatusCode = airSyncStatusCode;
 }
Ejemplo n.º 8
0
 public AttendeeData(string emailAddress, string displayName)
 {
     AirSyncDiagnostics.TraceInfo <string, string>(ExTraceGlobals.CommonTracer, null, "AttendeeData Created email={0} displayname={1}", emailAddress, displayName);
     this.emailAddress = emailAddress;
     this.displayName  = displayName;
 }
Ejemplo n.º 9
0
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            CalendarItem        calendarItem       = base.XsoItem as CalendarItem;
            IExceptionsProperty exceptionsProperty = srcProperty as IExceptionsProperty;
            XsoDataObject       xsoDataObject      = null;

            foreach (ExceptionInstance exceptionInstance in exceptionsProperty)
            {
                ExDateTime exDateTime  = ExTimeZone.UtcTimeZone.ConvertDateTime(exceptionInstance.ExceptionStartTime);
                ExDateTime exDateTime2 = calendarItem.ExTimeZone.ConvertDateTime(exDateTime);
                if (exceptionInstance.Deleted == 1)
                {
                    if (calendarItem.Id == null)
                    {
                        calendarItem.Save(SaveMode.ResolveConflicts);
                        calendarItem.Load();
                    }
                    try
                    {
                        this.ValidateCalendarItem(calendarItem);
                        calendarItem.DeleteOccurrenceByOriginalStartTime(exDateTime2);
                        continue;
                    }
                    catch (OccurrenceNotFoundException)
                    {
                        AirSyncDiagnostics.TraceDebug <ExDateTime>(ExTraceGlobals.XsoTracer, this, "Exception with OriginalStartTime: {0} already deleted.", exDateTime2);
                        continue;
                    }
                }
                if (xsoDataObject == null)
                {
                    xsoDataObject = this.schemaState.GetInnerXsoDataObject();
                }
                CalendarItemOccurrence calendarItemOccurrence = null;
                try
                {
                    if (calendarItem.Id != null)
                    {
                        this.ValidateCalendarItem(calendarItem);
                        calendarItemOccurrence = calendarItem.OpenOccurrenceByOriginalStartTime(exDateTime2, xsoDataObject.GetPrefetchProperties());
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "New calendar recurrence item added with exceptions.  Extra save (RPC to store) needed for this");
                        calendarItem.Save(SaveMode.ResolveConflicts);
                        calendarItem.Load();
                        this.ValidateCalendarItem(calendarItem);
                        calendarItemOccurrence = calendarItem.OpenOccurrenceByOriginalStartTime(exDateTime2, xsoDataObject.GetPrefetchProperties());
                    }
                    if (calendarItemOccurrence == null)
                    {
                        throw new ConversionException("Could not open the Calendar Occurrence using the Original StartTime");
                    }
                    calendarItemOccurrence.OpenAsReadWrite();
                    try
                    {
                        xsoDataObject.Bind(calendarItemOccurrence);
                        xsoDataObject.CopyFrom(exceptionInstance.ModifiedException);
                    }
                    finally
                    {
                        xsoDataObject.Unbind();
                    }
                    calendarItemOccurrence.Save(SaveMode.NoConflictResolution);
                }
                finally
                {
                    if (calendarItemOccurrence != null)
                    {
                        calendarItemOccurrence.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public ConversionException(HttpStatusCode httpStatusCode, string message, Exception innerException) : base(new LocalizedString(message), innerException)
 {
     AirSyncDiagnostics.TraceError <HttpStatusCode, string, string>(ExTraceGlobals.CommonTracer, this, "ConversionException has been thrown. HttpStatusCode:'{0}', Message:'{1}', InnerException: '{2}'", httpStatusCode, (message != null) ? message : string.Empty, (innerException != null) ? innerException.Message : string.Empty);
     this.httpStatusCode      = httpStatusCode;
     this.httpStatusCodeIsSet = true;
 }
        // Token: 0x060014E7 RID: 5351 RVA: 0x00079568 File Offset: 0x00077768
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            IPictureProperty pictureProperty = (IPictureProperty)srcProperty;

            if (string.IsNullOrEmpty(pictureProperty.PictureData))
            {
                this.InternalSetToDefault(srcProperty);
                return;
            }
            if (pictureProperty.PictureData.Length > 50000)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.ProtocolTracer, null, "The size of contact picture is bigger than 50000 base64 chars");
                throw new ConversionException("The size of contact picture is bigger than 50000 base64 chars");
            }
            AttachmentId attachmentId = null;
            Contact      contact      = base.XsoItem as Contact;

            contact.Load(new PropertyDefinition[]
            {
                XsoPictureProperty.hasPicture
            });
            object obj = contact.TryGetProperty(XsoPictureProperty.hasPicture);

            if (obj != null && obj is bool && (bool)obj)
            {
                foreach (AttachmentHandle handle in contact.AttachmentCollection)
                {
                    using (Attachment attachment = contact.AttachmentCollection.Open(handle))
                    {
                        attachment.Load(new PropertyDefinition[]
                        {
                            XsoPictureProperty.ispictureAttach
                        });
                        obj = attachment.TryGetProperty(XsoPictureProperty.ispictureAttach);
                        if (obj != null && obj is bool && (bool)obj)
                        {
                            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "XsoPictureProperty.InternalCopyFromModified(), picture attachment exists.");
                            attachmentId = attachment.Id;
                            break;
                        }
                    }
                }
            }
            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "XsoPictureProperty.InternalCopyFromModified(), creating a new picture attachment.");
            using (Attachment attachment2 = contact.AttachmentCollection.Create(AttachmentType.Stream))
            {
                attachment2[XsoPictureProperty.ispictureAttach]    = true;
                attachment2[AttachmentSchema.DisplayName]          = "ContactPicture.jpg";
                attachment2[XsoPictureProperty.attachFileName]     = string.Empty;
                attachment2[XsoPictureProperty.attachLongFileName] = "ContactPicture.jpg";
                attachment2[XsoPictureProperty.urlCompName]        = "ContactPicture.jpg";
                attachment2[XsoPictureProperty.attachExtension]    = "jpg";
                attachment2[XsoPictureProperty.attachFlags]        = 0;
                attachment2[XsoPictureProperty.attachmentFlags]    = 0;
                attachment2[XsoPictureProperty.attachmentHidden]   = false;
                attachment2[XsoPictureProperty.attachmentLinkId]   = 0;
                attachment2[XsoPictureProperty.attachEncoding]     = new byte[0];
                attachment2[XsoPictureProperty.exceptionStartTime] = new DateTime(4501, 1, 1);
                attachment2[XsoPictureProperty.exceptionEndTime]   = new DateTime(4501, 1, 1);
                contact[XsoPictureProperty.hasPicture]             = true;
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "XsoPictureProperty.InternalCopyFromModified(), writing the data to picture attachment.");
                using (Stream contentStream = ((StreamAttachment)attachment2).GetContentStream())
                {
                    contentStream.Position = 0L;
                    byte[] array = Convert.FromBase64String(pictureProperty.PictureData);
                    contentStream.Write(array, 0, array.Length);
                }
                attachment2.Save();
            }
            if (attachmentId != null)
            {
                contact.AttachmentCollection.Remove(attachmentId);
            }
        }
Ejemplo n.º 12
0
        // Token: 0x06001409 RID: 5129 RVA: 0x00073CB4 File Offset: 0x00071EB4
        public Stream GetData(BodyType type, long truncationSize, out long totalDataSize, out IEnumerable <AirSyncAttachmentInfo> attachments)
        {
            Item item = base.XsoItem as Item;

            attachments = null;
            if (item == null)
            {
                totalDataSize = 0L;
                return(null);
            }
            Stream stream;

            if (string.Equals(item.ClassName, "IPM.Note.SMIME", StringComparison.OrdinalIgnoreCase) && truncationSize != 0L)
            {
                string smimenotSupportedBodyHtml = XsoBodyPartProperty.GetSMIMENotSupportedBodyHtml(item.Session);
                stream        = new MemoryStream(Encoding.UTF8.GetBytes(smimenotSupportedBodyHtml));
                totalDataSize = stream.Length;
                return(stream);
            }
            switch (type)
            {
            case BodyType.None:
            case BodyType.PlainText:
            case BodyType.Rtf:
            case BodyType.Mime:
                throw new ConversionException(string.Format("Invalid body type requested: {0}", type));

            case BodyType.Html:
            {
                ConversationId valueOrDefault = item.GetValueOrDefault <ConversationId>(ItemSchema.ConversationId, null);
                if (valueOrDefault == null)
                {
                    throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, null, false)
                          {
                              ErrorStringForProtocolLogger = "NoConversationIdForItem"
                          };
                }
                Conversation conversation;
                bool         orCreateConversation = Command.CurrentCommand.GetOrCreateConversation(valueOrDefault, true, out conversation);
                if (conversation == null)
                {
                    throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, null, false)
                          {
                              ErrorStringForProtocolLogger = "ConversationObjectLoadFailedForItem"
                          };
                }
                if (orCreateConversation)
                {
                    conversation.LoadItemParts(new List <StoreObjectId>
                        {
                            item.StoreObjectId
                        });
                }
                IConversationTreeNode conversationTreeNode = null;
                if (!conversation.ConversationTree.TryGetConversationTreeNode(item.StoreObjectId, out conversationTreeNode))
                {
                    AirSyncDiagnostics.TraceError <StoreObjectId>(ExTraceGlobals.AirSyncTracer, this, "Cannot find itemId {0} in conversation tree!", item.StoreObjectId);
                    totalDataSize = 0L;
                    return(null);
                }
                bool flag = false;
                AirSyncDiagnostics.FaultInjectionTracer.TraceTest <bool>(3970313533U, ref flag);
                if (flag)
                {
                    totalDataSize = 0L;
                    return(null);
                }
                ItemPart itemPart = conversation.GetItemPart(item.StoreObjectId);
                if (!itemPart.DidLoadSucceed)
                {
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.AirSyncTracer, this, "ItemPart.DidLoadSucceed is false!");
                    stream        = null;
                    totalDataSize = 0L;
                    return(stream);
                }
                using (AirSyncStream airSyncStream = new AirSyncStream())
                {
                    try
                    {
                        using (HtmlWriter htmlWriter = new HtmlWriter(airSyncStream, Encoding.UTF8))
                        {
                            itemPart.WriteUniquePart(htmlWriter);
                            htmlWriter.Flush();
                        }
                    }
                    catch (TextConvertersException innerException)
                    {
                        throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, null, innerException, false);
                    }
                    airSyncStream.Seek(0L, SeekOrigin.Begin);
                    stream = new AirSyncStream();
                    uint streamHash;
                    StreamHelper.CopyStream(airSyncStream, stream, Encoding.UTF8, (int)truncationSize, true, out streamHash);
                    ((AirSyncStream)stream).StreamHash = (int)streamHash;
                    totalDataSize = ((truncationSize < 0L || airSyncStream.Length < truncationSize) ? stream.Length : airSyncStream.Length);
                    Dictionary <AttachmentId, AirSyncAttachmentInfo> dictionary = null;
                    if (itemPart.Attachments != null && itemPart.Attachments.Count > 0)
                    {
                        dictionary = itemPart.Attachments.ToDictionary((AttachmentInfo x) => x.AttachmentId, (AttachmentInfo x) => new AirSyncAttachmentInfo
                            {
                                AttachmentId = x.AttachmentId,
                                IsInline     = x.IsInline,
                                ContentId    = x.ContentId
                            });
                    }
                    Dictionary <AttachmentId, string> dictionary2;
                    Command.CurrentCommand.InlineAttachmentContentIdLookUp.TryGetValue(item.Id.ObjectId, out dictionary2);
                    if (dictionary2 != null)
                    {
                        if (dictionary != null)
                        {
                            foreach (KeyValuePair <AttachmentId, string> keyValuePair in dictionary2)
                            {
                                AirSyncAttachmentInfo airSyncAttachmentInfo;
                                if (dictionary.TryGetValue(keyValuePair.Key, out airSyncAttachmentInfo) && airSyncAttachmentInfo != null)
                                {
                                    airSyncAttachmentInfo.IsInline  = true;
                                    airSyncAttachmentInfo.ContentId = keyValuePair.Value;
                                }
                                else
                                {
                                    dictionary[keyValuePair.Key] = new AirSyncAttachmentInfo
                                    {
                                        AttachmentId = keyValuePair.Key,
                                        IsInline     = true,
                                        ContentId    = keyValuePair.Value
                                    };
                                }
                            }
                            attachments = dictionary.Values;
                        }
                        else
                        {
                            attachments = from inlineAttachment in dictionary2
                                          select new AirSyncAttachmentInfo
                            {
                                AttachmentId = inlineAttachment.Key,
                                IsInline     = true,
                                ContentId    = inlineAttachment.Value
                            };
                        }
                    }
                    else
                    {
                        attachments = ((dictionary != null) ? dictionary.Values : null);
                    }
                    return(stream);
                }
                break;
            }
            }
            stream        = null;
            totalDataSize = 0L;
            return(stream);
        }
        public IEnumerator <AttachmentData> GetEnumerator()
        {
            Item message = base.XsoItem as Item;

            if (message == null)
            {
                throw new UnexpectedTypeException("Item", base.XsoItem);
            }
            string baseId = null;

            if (this.idmapping != null)
            {
                baseId = this.idmapping[MailboxSyncItemId.CreateForNewItem(message.Id.ObjectId)];
            }
            if (baseId == null)
            {
                baseId = message.Id.ObjectId.ToBase64String();
            }
            if (base.XsoItem is MessageItem && ((MessageItem)message).IsRestricted)
            {
                object prop = message.TryGetProperty(MessageItemSchema.DRMLicense);
                if (prop is byte[][])
                {
                    byte[][] license = (byte[][])prop;
                    if (license.Length > 0)
                    {
                        yield return(new AttachmentData
                        {
                            AttMethod = 1,
                            AttSize = (long)license[0].Length,
                            DisplayName = "message.rpmsg.license",
                            AttName = HttpUtility.UrlEncode(baseId + ":DRMLicense")
                        });
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.XsoTracer, this, "The license property on the DRM message is incorrect. Length = {0}", license.Length);
                    }
                }
                else
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Failed to fetch the license property on the DRM message. Prop = {0}", new object[]
                    {
                        prop
                    });
                }
            }
            int index = -1;

            foreach (AttachmentHandle handle in message.AttachmentCollection)
            {
                index++;
                AttachmentData attachmentData = default(AttachmentData);
                Attachment     attachment     = null;
                try
                {
                    attachment = message.AttachmentCollection.Open(handle);
                    if (BodyUtility.IsClearSigned(message) && (string.Compare(attachment.FileName, "smime.p7m", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(attachment.ContentType, "multipart/signed", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        continue;
                    }
                    attachmentData.AttName = HttpUtility.UrlEncode(baseId + ":" + index);
                    if (string.IsNullOrEmpty(attachmentData.DisplayName))
                    {
                        if (!string.IsNullOrEmpty(attachment.FileName))
                        {
                            attachmentData.DisplayName = attachment.FileName;
                        }
                        else if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
                        {
                            using (Item itemAsReadOnly = ((ItemAttachment)attachment).GetItemAsReadOnly(null))
                            {
                                attachmentData.DisplayName = (itemAsReadOnly.TryGetProperty(ItemSchema.Subject) as string);
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(attachmentData.DisplayName))
                    {
                        attachmentData.DisplayName = "????";
                    }
                    attachmentData.AttMethod = (int)attachment.TryGetProperty(AttachmentSchema.AttachMethod);
                    attachmentData.AttSize   = attachment.Size;
                }
                finally
                {
                    if (attachment != null)
                    {
                        attachment.Dispose();
                        attachment = null;
                    }
                }
                yield return(attachmentData);
            }
            yield break;
        }
Ejemplo n.º 14
0
        // Token: 0x060010B2 RID: 4274 RVA: 0x0005D040 File Offset: 0x0005B240
        public static string GetRecipientString(RecipientCollection collection, RecipientItemType recipientItemType, IExchangePrincipal exchangePrincipal)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("Recipient collection null");
            }
            if (collection.Count == 0)
            {
                return(string.Empty);
            }
            int num = 0;

            Participant[] array  = new Participant[collection.Count];
            Participant[] array2 = new Participant[collection.Count];
            foreach (Recipient recipient in collection)
            {
                if (recipient == null)
                {
                    throw new ArgumentNullException("recipient is null");
                }
                array2[num] = recipient.Participant;
                if (recipient.Participant.RoutingType == "EX" && !string.IsNullOrEmpty(recipient.Participant.EmailAddress))
                {
                    Participant cachedParticipant = EmailAddressConverter.GetCachedParticipant(recipient.Participant.EmailAddress);
                    array[num++] = ((cachedParticipant == null) ? recipient.Participant : cachedParticipant);
                }
                else
                {
                    array[num++] = recipient.Participant;
                }
            }
            ParticipantUpdater.GetSMTPAddressesForParticipantsIfNecessary(array, collection);
            for (int i = 0; i < array.Length; i++)
            {
                Participant participant  = array2[i];
                Participant participant2 = array[i];
                if (participant.RoutingType != participant2.RoutingType)
                {
                    EmailAddressConverter.CacheParticipant(participant.EmailAddress, participant2);
                }
            }
            StringBuilder stringBuilder = new StringBuilder(collection.Count * 100);
            int           num2          = 0;

            foreach (Recipient recipient2 in collection)
            {
                Participant participant3 = array[num2++];
                if (recipientItemType == RecipientItemType.Unknown || recipient2.RecipientItemType == recipientItemType)
                {
                    if (participant3.DisplayName.StartsWith("\"") && participant3.DisplayName.EndsWith("\""))
                    {
                        stringBuilder.Append(participant3.DisplayName);
                        stringBuilder.Append(" <");
                    }
                    else
                    {
                        stringBuilder.Append('"');
                        stringBuilder.Append(participant3.DisplayName);
                        stringBuilder.Append("\" ");
                    }
                    stringBuilder.Append(EmailAddressConverter.LookupEmailAddressString(participant3, exchangePrincipal, true));
                    stringBuilder.Append(", ");
                }
                if (stringBuilder.Length > 32000)
                {
                    break;
                }
            }
            if (stringBuilder.Length > 1)
            {
                stringBuilder.Length -= 2;
            }
            AirSyncDiagnostics.TraceInfo <StringBuilder>(ExTraceGlobals.CommonTracer, null, "GetRecipientString = {0}", stringBuilder);
            return(stringBuilder.ToString());
        }
Ejemplo n.º 15
0
 // Token: 0x060010DD RID: 4317 RVA: 0x0005D92B File Offset: 0x0005BB2B
 public ExceptionInstance(ExDateTime exceptionStartTime, byte deleted)
 {
     AirSyncDiagnostics.TraceInfo <ExDateTime, byte>(ExTraceGlobals.CommonTracer, this, "ExceptionInstance Created exceptionStartTime={0} deleted={1}", exceptionStartTime, deleted);
     this.exceptionStartTime = exceptionStartTime;
     this.deleted            = deleted;
 }