+ public List<OutputType> getSupportedOutputTypes() {
+ return List.of(OutputType.PLAIN_TEXT, OutputType.JSON);
+ }
+
+ @Override
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
+ logger.info("Starting daemon in single-account mode for " + m.getSelfNumber());
+ final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
+ final var receiveMode = ns.<ReceiveMode>get("receive-mode");
+ final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
+ final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
+ final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
+
+ m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts));
+ addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
+
+ final Channel inheritedChannel;
+ try {
+ inheritedChannel = System.inheritedChannel();
+ if (inheritedChannel instanceof ServerSocketChannel serverChannel) {
+ logger.info("Using inherited socket: " + serverChannel.getLocalAddress());
+ runSocketSingleAccount(m, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ } catch (IOException e) {
+ throw new IOErrorException("Failed to use inherited socket", e);
+ }
+ final var socketFile = ns.<File>get("socket");
+ if (socketFile != null) {
+ final var address = UnixDomainSocketAddress.of(socketFile.toPath());
+ final var serverChannel = IOUtils.bindSocket(address);
+ runSocketSingleAccount(m, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ final var tcpAddress = ns.getString("tcp");
+ if (tcpAddress != null) {
+ final var address = IOUtils.parseInetSocketAddress(tcpAddress);
+ final var serverChannel = IOUtils.bindSocket(address);
+ runSocketSingleAccount(m, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ final var httpAddress = ns.getString("http");
+ if (httpAddress != null) {
+ final var address = IOUtils.parseInetSocketAddress(httpAddress);
+ final var handler = new HttpServerHandler(address, m);
+ try {
+ handler.init();
+ } catch (IOException ex) {
+ throw new IOErrorException("Failed to initialize HTTP Server", ex);
+ }
+ }
+ final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
+ if (isDbusSystem) {
+ runDbusSingleAccount(m, true, receiveMode != ReceiveMode.ON_START);
+ }
+ final var isDbusSession = Boolean.TRUE.equals(ns.getBoolean("dbus"));
+ if (isDbusSession || (
+ !isDbusSystem
+ && socketFile == null
+ && tcpAddress == null
+ && !(inheritedChannel instanceof ServerSocketChannel)
+ )) {
+ runDbusSingleAccount(m, false, receiveMode != ReceiveMode.ON_START);