Replies: 2 comments
|
Yes, currently it only supports interactive mode. You’re looking for a command-line argument approach, right? I think that’s a great idea, but sorry, I haven’t had the time to implement it yet. On another note, I added an ingest_timestamp (a millisecond timestamp of when it entered Bichon) to every email in version 1.x.x. Do you think we could use this to handle incremental exports? What are your thoughts? |
|
The incremental export could use UNIX Epoch Timestamp and put it into the export/filename. with the help of LLM i've drafted a Python pseudo-terminal wrapper that runs bichon-cli inside the Bichon Docker container and answers the interactive prompts automatically. The script simply automates the official interactive CLI flow. Will break as soon as the code path in this area is being changed. docker exec -it ix-bichon-bichon-1 bichon-cli #!/usr/bin/env python3
import os
import pty
import re
import select
import subprocess
import sys
import time
CONTAINER = os.environ.get("CONTAINER", "ix-bichon-bichon-1")
CONFIG = os.environ.get("CONFIG", "/data/bichon-data/bichon-cli-config.toml")
EXPORT_DIR = os.environ.get("EXPORT_DIR", "/data/bichon-data/exports")
# 0 = first account in the Bichon account-selection menu
# 1 = second account
# 2 = third account
ACCOUNT_INDEX = int(os.environ.get("ACCOUNT_INDEX", "0"))
def strip_ansi(text: str) -> str:
return re.sub(r"\x1b\[[0-?]*[ -/]*[@-~]", "", text)
def send(fd, value: str):
os.write(fd, value.encode("utf-8"))
def main():
subprocess.run(
["docker", "exec", CONTAINER, "mkdir", "-p", EXPORT_DIR],
check=True,
)
cmd = [
"docker",
"exec",
"-it",
CONTAINER,
"bichon-cli",
"--config",
CONFIG,
]
pid, fd = pty.fork()
if pid == 0:
os.execvp(cmd[0], cmd)
buffer = ""
sent_config_confirm = False
sent_export_menu = False
sent_account = False
sent_export_path = False
sent_final_confirm = False
last_output = time.time()
while True:
r, _, _ = select.select([fd], [], [], 1)
if fd in r:
try:
data = os.read(fd, 4096)
except OSError:
break
if not data:
break
sys.stdout.buffer.write(data)
sys.stdout.buffer.flush()
decoded = data.decode("utf-8", errors="replace")
buffer += decoded
buffer = buffer[-12000:]
clean = strip_ansi(buffer)
last_output = time.time()
if not sent_config_confirm and "Do you want to use this configuration" in clean:
send(fd, "\r")
sent_config_confirm = True
continue
if not sent_export_menu and "Select operation" in clean:
# Down arrow once = select "Export"
send(fd, "\x1b[B\r")
sent_export_menu = True
continue
if not sent_account and "Select the target account" in clean:
# Move down ACCOUNT_INDEX times, then Enter
send(fd, "\x1b[B" * ACCOUNT_INDEX + "\r")
sent_account = True
continue
if not sent_export_path and "Enter ABSOLUTE directory path" in clean:
send(fd, EXPORT_DIR + "\r")
sent_export_path = True
continue
if (
not sent_final_confirm
and "Export " in clean
and "emails to" in clean
and "?" in clean
):
send(fd, "\r")
sent_final_confirm = True
continue
if not sent_final_confirm and time.time() - last_output > 60:
print("\nERROR: Timeout while waiting for bichon-cli prompt.", file=sys.stderr)
try:
os.close(fd)
except OSError:
pass
return 1
_, status = os.waitpid(pid, 0)
return os.waitstatus_to_exitcode(status)
if __name__ == "__main__":
sys.exit(main())I've installed it on TrueNAS: sudo mkdir -p /mnt/ssd-pool/bichon/scripts sudo nano /mnt/ssd-pool/bichon/scripts/bichon_cli_mbox_auto.py sudo chmod +x /mnt/ssd-pool/bichon/scripts/bichon_cli_mbox_auto.py sudo ACCOUNT_INDEX=0 /mnt/ssd-pool/bichon/scripts/bichon_cli_mbox_auto.py Cron example: /mnt/ssd-pool/bichon/scripts/bichon_cli_mbox_auto.py >> /mnt/ssd-pool/bichon/exports/bichon-export.log 2>&1 |
Uh oh!
There was an error while loading. Please reload this page.
And with backups i am talking about the a full mbox export which can be used by any other application?
The current bichon-cli only exposes --config; after that it uses interactive prompts for config confirmation, operation selection, account selection, export path, and final confirmation. So i could think of create the config file once, then automate the interactive CLI with a pseudo-terminal wrapper. Howeber this seem cumbersome and if something changes in later versions it will silently break.
FeatureRequest here: #274
All reactions