本文整理汇总了Python中inbox.models.backends.imap.ImapUid.update_labels方法的典型用法代码示例。如果您正苦于以下问题:Python ImapUid.update_labels方法的具体用法?Python ImapUid.update_labels怎么用?Python ImapUid.update_labels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.models.backends.imap.ImapUid
的用法示例。
在下文中一共展示了ImapUid.update_labels方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_imap_message
# 需要导入模块: from inbox.models.backends.imap import ImapUid [as 别名]
# 或者: from inbox.models.backends.imap.ImapUid import update_labels [as 别名]
def create_imap_message(db_session, account, folder, msg):
"""
IMAP-specific message creation logic.
Returns
-------
imapuid : inbox.models.backends.imap.ImapUid
New db object, which links to new Message and Block objects through
relationships. All new objects are uncommitted.
"""
new_message = Message.create_from_synced(
account=account, mid=msg.uid, folder_name=folder.name, received_date=msg.internaldate, body_string=msg.body
)
# Check to see if this is a copy of a message that was first created
# by the Nylas API. If so, don't create a new object; just use the old one.
existing_copy = reconcile_message(new_message, db_session)
if existing_copy is not None:
new_message = existing_copy
imapuid = ImapUid(account=account, folder=folder, msg_uid=msg.uid, message=new_message)
imapuid.update_flags(msg.flags)
if msg.g_labels is not None:
imapuid.update_labels(msg.g_labels)
# Update the message's metadata
with db_session.no_autoflush:
is_draft = imapuid.is_draft and (folder.canonical_name == "drafts" or folder.canonical_name == "all")
update_message_metadata(db_session, account, new_message, is_draft)
update_contacts_from_message(db_session, new_message, account.namespace)
return imapuid
示例2: __deduplicate_message_object_creation
# 需要导入模块: from inbox.models.backends.imap import ImapUid [as 别名]
# 或者: from inbox.models.backends.imap.ImapUid import update_labels [as 别名]
def __deduplicate_message_object_creation(self, db_session, raw_messages,
account):
"""
We deduplicate messages based on g_msgid: if we've previously saved a
Message object for this raw message, we don't create a new one. But we
do create a new ImapUid, associate it to the message, and update flags
and categories accordingly.
Note: we could do this prior to downloading the actual message
body, but that's really more complicated than it's worth. This
operation is not super common unless you're regularly moving lots
of messages to trash or spam, and even then the overhead of just
downloading the body is generally not that high.
"""
new_g_msgids = {msg.g_msgid for msg in raw_messages}
existing_g_msgids = g_msgids(self.namespace_id, db_session,
in_=new_g_msgids)
brand_new_messages = [m for m in raw_messages if m.g_msgid not in
existing_g_msgids]
previously_synced_messages = [m for m in raw_messages if m.g_msgid in
existing_g_msgids]
if previously_synced_messages:
log.info('saving new uids for existing messages',
count=len(previously_synced_messages))
account = Account.get(self.account_id, db_session)
folder = Folder.get(self.folder_id, db_session)
for raw_message in previously_synced_messages:
message_obj = db_session.query(Message).filter(
Message.namespace_id == self.namespace_id,
Message.g_msgid == raw_message.g_msgid).first()
if message_obj is None:
log.warning(
'Message disappeared while saving new uid',
g_msgid=raw_message.g_msgid,
uid=raw_message.uid)
brand_new_messages.append(raw_message)
continue
already_have_uid = (
(raw_message.uid, self.folder_id) in
{(u.msg_uid, u.folder_id) for u in message_obj.imapuids}
)
if already_have_uid:
log.warning('Skipping existing UID for message',
uid=raw_message.uid, message_id=message_obj.id)
continue
uid = ImapUid(account=account,
folder=folder,
msg_uid=raw_message.uid,
message=message_obj)
uid.update_flags(raw_message.flags)
uid.update_labels(raw_message.g_labels)
common.update_message_metadata(
db_session, account, message_obj, uid.is_draft)
db_session.commit()
return brand_new_messages
示例3: create_imap_message
# 需要导入模块: from inbox.models.backends.imap import ImapUid [as 别名]
# 或者: from inbox.models.backends.imap.ImapUid import update_labels [as 别名]
def create_imap_message(db_session, log, account, folder, msg):
"""
IMAP-specific message creation logic.
This is the one function in this file that gets to take an account
object instead of an account_id, because we need to relate the
account to ImapUids for versioning to work, since it needs to look
up the namespace.
Returns
-------
imapuid : inbox.models.tables.imap.ImapUid
New db object, which links to new Message and Block objects through
relationships. All new objects are uncommitted.
"""
new_message = Message.create_from_synced(account=account, mid=msg.uid,
folder_name=folder.name,
received_date=msg.internaldate,
body_string=msg.body)
# Check to see if this is a copy of a message that was first created
# by the Inbox API. If so, don't create a new object; just use the old one.
existing_copy = reconcile_message(new_message, db_session)
if existing_copy is not None:
new_message = existing_copy
imapuid = ImapUid(account=account, folder=folder, msg_uid=msg.uid,
message=new_message)
imapuid.update_flags(msg.flags)
if msg.g_labels is not None:
imapuid.update_labels(msg.g_labels)
# Update the message's metadata
with db_session.no_autoflush:
update_message_metadata(db_session, account, new_message,
imapuid.is_draft)
update_contacts_from_message(db_session, new_message, account.namespace)
return imapuid