首页 > 解决方案 > 无法使用 exchagelib 代码删除房间日历项目

问题描述

我的问题看起来很奇怪。交换 2010 SP1。代码在房间日历中查找冲突记录并应将其删除。代码如下:

#DELEGATE also doesn't work
 roomAccount = Account(primary_smtp_address=room_mailbox, config=config,
                              autodiscover=False, access_type=IMPERSONATION)
 items = roomAccount.calendar.filter(start__gt=now_with_past) 
 for item in items:
     if (start_dt_ews != start_dt_remote or item.subject != remote_record_subject or duration != remote_record_duration):
                            has_conflicts = detect_conflicts(roomAccount, item)
                            if has_conflicts:                            
                                process_conflict(item, 'update_conflict')
                                remove_meeting_data(item, item.organizer)
                                continue                                

def detect_conflicts(roomAccount, item):
    try:
        has_conflicts = False
        if item.conflicting_meeting_count > 0:
            if item.start_dt != item.start:
                has_conflicts = True
        return has_conflicts
    except Exception as e:
        trace_back = traceback.format_exc()
        log_str = "Error in process_service " + str(e) + " " + str(trace_back)
        Logger.error(log_str)
        return False    

def process_conflict(item, category):
    if item.recurrence:
        conflict_notify_and_delete(item, category, True)
    else:
        conflict_notify_and_delete(item, category, False)
        Logger.error(item.subject + " meeting conflict error.")     
        
def conflict_notify_and_delete(item, category, serial):
    send_email(item.organizer, category, (item.subject))
    try:
        if serial:
            item.delete(affected_task_occurrences=ALL_OCCURRENCIES)
            item.save()
        else:               
            # doesn't  work
            item.delete(send_meeting_cancellations=SEND_TO_NONE, 
 affected_task_occurrences=ALL_OCCURRENCIES)            
            # or also doesn't  work
            item.delete()           
            # or raise trash folder absense error.
            item.move_to_trash()

            # or raise trash folder absense error again.
            item.soft_delete()
            
            #abrakadabra atempts with rescheduling and subsequent deletion raise
            # "Set action is invalid for property. (field: FieldURI(field_uri='calendar:StartTimeZone'))"  error            
            item.start = UTC_NOW() + timedelta(days=6000)
            item.save(update_fields=['start'])
            item.delete()

关于这一切的最奇怪的事实 - 任何 delete() 处理都只是沉默 - 没有错误,没有例外,一切看起来都很好,而实际上没有任何修改被删除。第二个最奇怪的事实 - 有时但不是每次我在 item.delete() 之后尝试 item.save() 时,它会引发“AttributeError(“在仅保存模式下必须提供文件夹”)”,但可能会立即删除项目。并且可能不是:((这种奇怪的事情只发生在处理冲突日历项目的部分代码中。不冲突的项目处理很好 - 删除和修改都可以。

有没有人知道,发生了什么以及如何最终从会议室日历中删除冲突记录而不取消组织者日历中的会议 - 我们不希望用户在其中丢失他的项目和信息?我试图用谷歌搜索可能导致这种奇怪但没有运气的 EWS 设置:(

标签: exchangewebservicesexchangelib

解决方案


推荐阅读