mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-02-26 18:17:09 +00:00
mailpile beta
This commit is contained in:
parent
4f57c62681
commit
d14a6ba9da
@ -9,7 +9,7 @@
|
|||||||
# When a user logs in, a new Mailpile instance is forked and we
|
# When a user logs in, a new Mailpile instance is forked and we
|
||||||
# proxy to that Mailpile for that user's session.
|
# proxy to that Mailpile for that user's session.
|
||||||
|
|
||||||
import sys, os, os.path, re, urllib.request, urllib.parse, urllib.error, time
|
import sys, os, os.path, re, urllib.request, urllib.parse, urllib.error, time, subprocess
|
||||||
|
|
||||||
from flask import Flask, request, session, render_template, redirect, abort
|
from flask import Flask, request, session, render_template, redirect, abort
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@ -160,7 +160,7 @@ def proxy_request_to_mailpile(path):
|
|||||||
|
|
||||||
if content_type.startswith("text/html"):
|
if content_type.startswith("text/html"):
|
||||||
# Rewrite URLs in HTML responses.
|
# Rewrite URLs in HTML responses.
|
||||||
body = re.sub(rb" (href|src|HREF|SRC)=('[^']*'|\"[^\"]*\")",
|
body = re.sub(rb" (href|src|HREF|SRC|action)=('[^']*'|\"[^\"]*\")",
|
||||||
lambda m : b' ' + m.group(1) + b'=' + m.group(2)[0:1] + rewrite_url(m.group(2)[1:-1]) + m.group(2)[0:1],
|
lambda m : b' ' + m.group(1) + b'=' + m.group(2)[0:1] + rewrite_url(m.group(2)[1:-1]) + m.group(2)[0:1],
|
||||||
body)
|
body)
|
||||||
|
|
||||||
@ -193,15 +193,8 @@ def get_mailpile_port(emailaddr):
|
|||||||
|
|
||||||
def spawn_mailpile(emailaddr):
|
def spawn_mailpile(emailaddr):
|
||||||
# Spawn a new instance of Mailpile that will automatically die
|
# Spawn a new instance of Mailpile that will automatically die
|
||||||
# when this process exits (because then we've lost track of the
|
# when this process exits because it'll be reading from a pipe
|
||||||
# Mailpile instances we started).
|
# connected to this process.
|
||||||
#
|
|
||||||
# To do that, use an inspired idea from http://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits
|
|
||||||
# which uses an intermediate process that catches a SIGPIPE from the parent.
|
|
||||||
# We don't need an intermediate process because Mailpile is waiting
|
|
||||||
# for commands on STDIN. By giving it a STDIN that is a file descriptor
|
|
||||||
# that we never write to but keep open, the process should die as soon
|
|
||||||
# as this process exits due to a SIGPIPE.
|
|
||||||
|
|
||||||
# Prepare mailpile.
|
# Prepare mailpile.
|
||||||
|
|
||||||
@ -215,29 +208,22 @@ def spawn_mailpile(emailaddr):
|
|||||||
utils.shell("check_call", cmd, env={ "MAILPILE_HOME": mp_home })
|
utils.shell("check_call", cmd, env={ "MAILPILE_HOME": mp_home })
|
||||||
|
|
||||||
os.makedirs(mp_home, exist_ok=True)
|
os.makedirs(mp_home, exist_ok=True)
|
||||||
mp("--setup")
|
mp("add", maildir)
|
||||||
mp("--add", maildir, "--rescan", "all")
|
mp("rescan")
|
||||||
|
mp("set", "profiles.0.email=%s" % emailaddr)
|
||||||
# Create OS file descriptors for two ends of a pipe.
|
mp("set", "profiles.0.name=%s" % emailaddr)
|
||||||
# The pipe's write end remains open until the process dies, which is right.
|
mp("set", "sys.http_port=%d" % port)
|
||||||
# But we close the read end immediately.
|
|
||||||
|
|
||||||
pipe_r, pipe_w = os.pipe()
|
|
||||||
os.close(pipe_r)
|
|
||||||
|
|
||||||
# Span mailpile in a way that lets us control its stdin.
|
# Span mailpile in a way that lets us control its stdin.
|
||||||
mailpile_proc = \
|
mailpile_proc = \
|
||||||
utils.shell("Popen",
|
subprocess.Popen(
|
||||||
[
|
[
|
||||||
os.path.join(os.path.dirname(__file__), '../externals/Mailpile/mp'),
|
os.path.join(os.path.dirname(__file__), '../externals/Mailpile/mp'),
|
||||||
"--www",
|
],
|
||||||
"--set", "sys.http_port=%d" % port,
|
stdin=subprocess.PIPE,
|
||||||
"--set", "profiles.0.email=%s" % emailaddr,
|
#stdout=subprocess.DEVNULL,
|
||||||
"--set", "profiles.0.name=%s" % emailaddr,
|
env={ "MAILPILE_HOME": mp_home }
|
||||||
],
|
)
|
||||||
stdin=pipe_w,
|
|
||||||
env={ "MAILPILE_HOME": mp_home }
|
|
||||||
)
|
|
||||||
|
|
||||||
# Give mailpile time to start before trying to send over a request.
|
# Give mailpile time to start before trying to send over a request.
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
Loading…
Reference in New Issue
Block a user