aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVosjedev <vosje@vosjedev.net>2025-11-06 15:38:30 +0100
committerVosjedev <vosje@vosjedev.net>2025-11-06 15:38:30 +0100
commit113005e39085a5bb3c6d53fa2964388c3eb0a395 (patch)
tree2b43b0b00751636baa7cee17e3a96c3ada6ac97c
parent8d8375b2c309c54a734e2d3b8cbd9b35ac664e74 (diff)
downloadacit-113005e39085a5bb3c6d53fa2964388c3eb0a395.tar.gz
acit-113005e39085a5bb3c6d53fa2964388c3eb0a395.tar.bz2
acit-113005e39085a5bb3c6d53fa2964388c3eb0a395.tar.xz
imapplugin: manage smtp queue
-rw-r--r--src/acit/imapplugin.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/acit/imapplugin.py b/src/acit/imapplugin.py
index 289494a..b38f77c 100644
--- a/src/acit/imapplugin.py
+++ b/src/acit/imapplugin.py
@@ -13,7 +13,9 @@ from imap_tools import MailBox, MailMessage
from .imap_pool import MailBoxPool, PoolEmpty
from .db import DBPoolManager
-from .types import Site
+from .types import Site, Bug
+
+from .smtpplugin import SmtpPlugin
class ImapPlugin(plugins.SimplePlugin):
def __init__(self,bus,dbpool:DBPoolManager,site:Site):
@@ -26,20 +28,14 @@ class ImapPlugin(plugins.SimplePlugin):
self.imap_pass=getenv("ACIT_IMAP_PASS")
self.imap_port=int(getenv("ACIT_IMAP_PORT",993))
- self.smtp_server=getenv("ACIT_SMTP_SERVER")
- self.smtp_user=getenv("ACIT_SMTP_USER")
- self.smtp_pass=getenv("ACIT_SMTP_PASS")
- self.smtp_port=int(getenv("ACIT_SMTP_PORT",0))
-
- if not ( self.imap_server and self.imap_user and self.imap_pass and self.smtp_server and self.smtp_user and self.smtp_pass ):
- raise ValueError("Missing ACIT_IMAP_SERVER, ACIT_IMAP_USER, ACIT_SMTP_SERVER, or ACIT_SMTP_USER")
+ if not ( self.imap_server and self.imap_user and self.imap_pass):
+ raise ValueError("Missing ACIT_IMAP_SERVER, ACIT_IMAP_USER, or ACIT_IMAP_PASS")
# end block
self.mlog("IMAP config: %s @ %s : %d"%(self.imap_user,self.imap_server,self.imap_port))
# block: make storage attributes
self.mailin_thread=None
- self.mailout_thread=None
self.stopping=threading.Event()
self.mailout_queue=Queue()
@@ -50,6 +46,8 @@ class ImapPlugin(plugins.SimplePlugin):
host=self.imap_server,port=self.imap_port,username=self.imap_user,password=self.imap_pass,
connection_n=int(getenv("ACIT_IMAP_POOL_SIZE",4))
)
+
+ self.smtp=SmtpPlugin()
self.index_lock=threading.Lock()
@@ -58,7 +56,6 @@ class ImapPlugin(plugins.SimplePlugin):
# block: prepare threads
self.stopping.clear()
self.mailin_thread=threading.Thread(target=self.imap_loop_controller)
- self.mailout_thread=threading.Thread(target=self.smtp_loop)
# end block
# block: fetch configuration around email address usage from env
@@ -77,6 +74,8 @@ class ImapPlugin(plugins.SimplePlugin):
self.addr_regex=self.emailname+r"+[^@#]*(#[0-9]*)?@"+self.emaildomain.replace(".","\\.")
# end block
+ self.smtp.domain=self.emaildomain
+
self.mlog("Starting mailbox pool. This can take a while.")
self.mbpool.open()
pool=self.mbpool.get_pool_size()
@@ -99,7 +98,7 @@ class ImapPlugin(plugins.SimplePlugin):
self.mlog("Starting threads")
self.mailin_thread.start()
- #self.mailout_thread.start()
+ self.smtp.start()
self.mlog("Done")
@@ -344,10 +343,12 @@ class ImapPlugin(plugins.SimplePlugin):
"Sets stopping signal, waits for all threads to stop"
self.mlog("Stopping. This can take a while.")
self.stopping.set()
- for thread in ( self.mailin_thread, self.mailout_thread ):
+ for thread in ( self.mailin_thread, ):
if thread.is_alive() and not thread==threading.current_thread():
self.mlog("Waiting for thread: %s"%thread.name)
thread.join()
+ self.mlog("Stopping SMTP worker")
+ self.smtp.stop()
self.mlog("Closing IMAP pool")
self.mbpool.close()
self.mlog("Stopped")