move display_list_item fn to Mail.print
This commit is contained in:
parent
1f98e6627d
commit
ce1aad5454
67
pqm
67
pqm
@ -230,6 +230,35 @@ class Mail:
|
|||||||
queue.append(mail)
|
queue.append(mail)
|
||||||
return queue
|
return queue
|
||||||
|
|
||||||
|
def print(self, *, verbose: bool, out: typing.TextIO = sys.stdout) -> None:
|
||||||
|
flag = CLI.QUEUE_FLAGS.get(self.queue_name, ' ')
|
||||||
|
if verbose:
|
||||||
|
print(
|
||||||
|
f"{self.queue_id + flag:<17s} {self.message_size:>8d} {self.arrival_time:%a %b %d %H:%M:%S} {self.sender:<60s}",
|
||||||
|
file=out,
|
||||||
|
)
|
||||||
|
if not self.recipients:
|
||||||
|
print(f"{'':21}No recipients listed for this mail?", file=out)
|
||||||
|
for recpt in self.recipients:
|
||||||
|
print(f"{'':21}{recpt.address}", file=out)
|
||||||
|
if recpt.delay_reason:
|
||||||
|
print(f"{'':29}{recpt.delay_reason}", file=out)
|
||||||
|
else:
|
||||||
|
cnt_recpts = len(self.recipients)
|
||||||
|
if cnt_recpts:
|
||||||
|
last_recpt = self.recipients[-1].address
|
||||||
|
print(
|
||||||
|
f"{self.queue_id + flag:<17s} {self.message_size:>8d} {self.arrival_time:%a %b %d %H:%M:%S} "
|
||||||
|
f"{self.sender:<60s} (Targets: {cnt_recpts}, last: {last_recpt})",
|
||||||
|
file=out,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"{self.queue_id + flag:<17s} {self.message_size:>8d} {self.arrival_time:%a %b %d %H:%M:%S} "
|
||||||
|
f"{self.sender:<60s} (No recipients listed for this mail?)",
|
||||||
|
file=out,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# abstract collection/cluster of postfix nodes (or just a single one)
|
# abstract collection/cluster of postfix nodes (or just a single one)
|
||||||
class Source(abc.ABC):
|
class Source(abc.ABC):
|
||||||
@ -1334,32 +1363,6 @@ class CLI:
|
|||||||
QueueName.DEFERRED: ' ',
|
QueueName.DEFERRED: ' ',
|
||||||
}
|
}
|
||||||
|
|
||||||
def display_list_item(self, *, item: Mail, verbose: bool) -> None:
|
|
||||||
flag = CLI.QUEUE_FLAGS.get(item.queue_name, ' ')
|
|
||||||
if verbose:
|
|
||||||
print(
|
|
||||||
f"{item.queue_id + flag:<17s} {item.message_size:>8d} {item.arrival_time:%a %b %d %H:%M:%S} {item.sender:<60s}"
|
|
||||||
)
|
|
||||||
if not item.recipients:
|
|
||||||
print(f"{'':21}No recipients listed for this mail?")
|
|
||||||
for recpt in item.recipients:
|
|
||||||
print(f"{'':21}{recpt.address}")
|
|
||||||
if recpt.delay_reason:
|
|
||||||
print(f"{'':29}{recpt.delay_reason}")
|
|
||||||
else:
|
|
||||||
cnt_recpts = len(item.recipients)
|
|
||||||
if cnt_recpts:
|
|
||||||
last_recpt = item.recipients[-1].address
|
|
||||||
print(
|
|
||||||
f"{item.queue_id + flag:<17s} {item.message_size:>8d} {item.arrival_time:%a %b %d %H:%M:%S} "
|
|
||||||
f"{item.sender:<60s} (Targets: {cnt_recpts}, last: {last_recpt})"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
print(
|
|
||||||
f"{item.queue_id + flag:<17s} {item.message_size:>8d} {item.arrival_time:%a %b %d %H:%M:%S} "
|
|
||||||
f"{item.sender:<60s} (No recipients listed for this mail?)"
|
|
||||||
)
|
|
||||||
|
|
||||||
async def list_impl(self, *, args: str, verbose: bool, all: bool) -> None:
|
async def list_impl(self, *, args: str, verbose: bool, all: bool) -> None:
|
||||||
flt: AndFilter
|
flt: AndFilter
|
||||||
if args:
|
if args:
|
||||||
@ -1380,7 +1383,7 @@ class CLI:
|
|||||||
else:
|
else:
|
||||||
show_filter = flt
|
show_filter = flt
|
||||||
for item in show_filter.filter(await self.source.get_list()):
|
for item in show_filter.filter(await self.source.get_list()):
|
||||||
self.display_list_item(item=item, verbose=verbose)
|
item.print(verbose=verbose)
|
||||||
|
|
||||||
async def _print_mails_with_ids_for_ack(self, given_ids: typing.Iterable[str]) -> list[Mail]:
|
async def _print_mails_with_ids_for_ack(self, given_ids: typing.Iterable[str]) -> list[Mail]:
|
||||||
mails = {
|
mails = {
|
||||||
@ -1392,7 +1395,7 @@ class CLI:
|
|||||||
for queue_id in given_ids:
|
for queue_id in given_ids:
|
||||||
item = mails.get(queue_id, None)
|
item = mails.get(queue_id, None)
|
||||||
if item:
|
if item:
|
||||||
self.display_list_item(item=item, verbose=False)
|
item.print(verbose=False)
|
||||||
verified_list.append(item)
|
verified_list.append(item)
|
||||||
else:
|
else:
|
||||||
missing.append(queue_id)
|
missing.append(queue_id)
|
||||||
@ -1574,7 +1577,7 @@ class CLI:
|
|||||||
async def delete_impl(self, flt: Filter) -> None:
|
async def delete_impl(self, flt: Filter) -> None:
|
||||||
mails = list(flt.filter(await self.source.get_list()))
|
mails = list(flt.filter(await self.source.get_list()))
|
||||||
for item in mails:
|
for item in mails:
|
||||||
self.display_list_item(item=item, verbose=False)
|
item.print(verbose=False)
|
||||||
ack = input_ack("Really delete those mails (y/N)? ")
|
ack = input_ack("Really delete those mails (y/N)? ")
|
||||||
if ack.lower()[:1] != "y":
|
if ack.lower()[:1] != "y":
|
||||||
return
|
return
|
||||||
@ -1681,7 +1684,7 @@ class CLI:
|
|||||||
flt = self.current_filter
|
flt = self.current_filter
|
||||||
mails = list(flt.filter(await self.source.get_list()))
|
mails = list(flt.filter(await self.source.get_list()))
|
||||||
for item in mails:
|
for item in mails:
|
||||||
self.display_list_item(item=item, verbose=False)
|
item.print(verbose=False)
|
||||||
ack = input_ack("Really expire and flush (if in deferred queue) those mails (y/N)? ")
|
ack = input_ack("Really expire and flush (if in deferred queue) those mails (y/N)? ")
|
||||||
if ack.lower()[:1] != "y":
|
if ack.lower()[:1] != "y":
|
||||||
return
|
return
|
||||||
@ -1707,7 +1710,7 @@ class CLI:
|
|||||||
flt = self.current_filter
|
flt = self.current_filter
|
||||||
mails = list(flt.filter(await self.source.get_list()))
|
mails = list(flt.filter(await self.source.get_list()))
|
||||||
for item in mails:
|
for item in mails:
|
||||||
self.display_list_item(item=item, verbose=False)
|
item.print(verbose=False)
|
||||||
ack = input_ack("Really expire, release and flush (if in deferred/hold queue) those mails (y/N)? ")
|
ack = input_ack("Really expire, release and flush (if in deferred/hold queue) those mails (y/N)? ")
|
||||||
if ack.lower()[:1] != "y":
|
if ack.lower()[:1] != "y":
|
||||||
return
|
return
|
||||||
@ -1733,7 +1736,7 @@ class CLI:
|
|||||||
flt = self.current_filter
|
flt = self.current_filter
|
||||||
mails = list(flt.filter(await self.source.get_list()))
|
mails = list(flt.filter(await self.source.get_list()))
|
||||||
for item in mails:
|
for item in mails:
|
||||||
self.display_list_item(item=item, verbose=False)
|
item.print(verbose=False)
|
||||||
ack = input_ack("Really expire those mails (y/N)? ")
|
ack = input_ack("Really expire those mails (y/N)? ")
|
||||||
if ack.lower()[:1] != "y":
|
if ack.lower()[:1] != "y":
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user