mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
simplify handle_set method for dictproxy subclasses
This commit is contained in:
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
## untagged
|
## untagged
|
||||||
|
|
||||||
|
- fix metadata dictproxy which would confuse transactions
|
||||||
|
resulting in missed notifications and other issues.
|
||||||
|
([#393](https://github.com/deltachat/chatmail/pull/388))
|
||||||
|
([#394](https://github.com/deltachat/chatmail/pull/389))
|
||||||
|
|
||||||
- add optional "imap_rawlog" config option. If true,
|
- add optional "imap_rawlog" config option. If true,
|
||||||
.in/.out files are created in user home dirs
|
.in/.out files are created in user home dirs
|
||||||
containing the imap protocol messages.
|
containing the imap protocol messages.
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ class DictProxy:
|
|||||||
elif short_command == "C":
|
elif short_command == "C":
|
||||||
return self.handle_commit_transaction(transaction_id, parts, transactions)
|
return self.handle_commit_transaction(transaction_id, parts, transactions)
|
||||||
elif short_command == "S":
|
elif short_command == "S":
|
||||||
return self.handle_set(transaction_id, parts, transactions)
|
addr = transactions[transaction_id]["addr"]
|
||||||
|
if not self.handle_set(addr, parts):
|
||||||
|
transactions[transaction_id]["res"] = "F\n"
|
||||||
|
logging.error(f"dictproxy-set failed for {addr!r}: {msg!r}")
|
||||||
|
|
||||||
def handle_lookup(self, parts):
|
def handle_lookup(self, parts):
|
||||||
logging.warning(f"lookup ignored: {parts!r}")
|
logging.warning(f"lookup ignored: {parts!r}")
|
||||||
@@ -59,11 +62,10 @@ class DictProxy:
|
|||||||
addr = parts[1]
|
addr = parts[1]
|
||||||
transactions[transaction_id] = dict(addr=addr, res="O\n")
|
transactions[transaction_id] = dict(addr=addr, res="O\n")
|
||||||
|
|
||||||
def handle_set(self, transaction_id, parts, transactions):
|
def handle_set(self, addr, parts):
|
||||||
# For documentation on key structure see
|
# For documentation on key structure see
|
||||||
# https://github.com/dovecot/core/blob/main/src/lib-storage/mailbox-attribute.h
|
# https://github.com/dovecot/core/blob/main/src/lib-storage/mailbox-attribute.h
|
||||||
|
return False
|
||||||
transactions[transaction_id]["res"] = "F\n"
|
|
||||||
|
|
||||||
def handle_commit_transaction(self, transaction_id, parts, transactions):
|
def handle_commit_transaction(self, transaction_id, parts, transactions):
|
||||||
# return whatever "set" command(s) set as result.
|
# return whatever "set" command(s) set as result.
|
||||||
|
|||||||
@@ -9,20 +9,19 @@ class LastLoginDictProxy(DictProxy):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def handle_set(self, transaction_id, parts, transactions):
|
def handle_set(self, addr, parts):
|
||||||
keyname = parts[1].split("/")
|
keyname = parts[1].split("/")
|
||||||
value = parts[2] if len(parts) > 2 else ""
|
value = parts[2] if len(parts) > 2 else ""
|
||||||
addr = transactions[transaction_id]["addr"]
|
|
||||||
if keyname[0] == "shared" and keyname[1] == "last-login":
|
if keyname[0] == "shared" and keyname[1] == "last-login":
|
||||||
if addr.startswith("echo@"):
|
if addr.startswith("echo@"):
|
||||||
return
|
return True
|
||||||
addr = keyname[2]
|
addr = keyname[2]
|
||||||
timestamp = int(value)
|
timestamp = int(value)
|
||||||
user = self.config.get_user(addr)
|
user = self.config.get_user(addr)
|
||||||
user.set_last_login_timestamp(timestamp)
|
user.set_last_login_timestamp(timestamp)
|
||||||
else:
|
return True
|
||||||
# Transaction failed.
|
|
||||||
transactions[transaction_id]["res"] = "F\n"
|
return False
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -62,24 +62,19 @@ class MetadataDictProxy(DictProxy):
|
|||||||
logging.warning(f"lookup ignored: {parts!r}")
|
logging.warning(f"lookup ignored: {parts!r}")
|
||||||
return "N\n"
|
return "N\n"
|
||||||
|
|
||||||
def handle_set(self, transaction_id, parts, transactions):
|
def handle_set(self, addr, parts):
|
||||||
# For documentation on key structure see
|
# For documentation on key structure see
|
||||||
# https://github.com/dovecot/core/blob/main/src/lib-storage/mailbox-attribute.h
|
# https://github.com/dovecot/core/blob/main/src/lib-storage/mailbox-attribute.h
|
||||||
keyname = parts[1].split("/")
|
keyname = parts[1].split("/")
|
||||||
value = parts[2] if len(parts) > 2 else ""
|
value = parts[2] if len(parts) > 2 else ""
|
||||||
addr = transactions[transaction_id]["addr"]
|
|
||||||
if keyname[0] == "priv" and keyname[2] == self.metadata.DEVICETOKEN_KEY:
|
if keyname[0] == "priv" and keyname[2] == self.metadata.DEVICETOKEN_KEY:
|
||||||
self.metadata.add_token_to_addr(addr, value)
|
self.metadata.add_token_to_addr(addr, value)
|
||||||
|
return True
|
||||||
elif keyname[0] == "priv" and keyname[2] == "messagenew":
|
elif keyname[0] == "priv" and keyname[2] == "messagenew":
|
||||||
self.notifier.new_message_for_addr(addr, self.metadata)
|
self.notifier.new_message_for_addr(addr, self.metadata)
|
||||||
else:
|
return True
|
||||||
# Transaction failed.
|
|
||||||
try:
|
return False
|
||||||
transactions[transaction_id]["res"] = "F\n"
|
|
||||||
except KeyError:
|
|
||||||
logging.error(
|
|
||||||
f"could not mark tx as failed: {transaction_id} {transactions}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user