Skip to content

Instantly share code, notes, and snippets.

@kboss
Created March 26, 2024 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kboss/7c9593f0fd9219406226c4f11256b98a to your computer and use it in GitHub Desktop.
Save kboss/7c9593f0fd9219406226c4f11256b98a to your computer and use it in GitHub Desktop.
Simple Python script for mass subscribing from a plaintext file to a mlmmj list. (Tested w/ Debian 12 @ hostsharing.net)
import click
import subprocess
listhome = '/home/pacs/xyz00/users/list/mlmmj'
@click.command()
@click.option("--file", prompt="Filename",
help="The file with the recipients (one per line). Must be in the same directory.")
@click.option("--mlist", prompt="Listname",
help="The name of the mlmmj list to subscribe to.")
# TODO: Implement -c / -C choice to request confirmation by subscriber
def importer(file, mlist):
"""Subscribes many recipients line-wise from a plaintext FILE to the mlmmj list MLIST."""
with open(file, 'r') as importfile:
click.echo('Found file to import... ', nl=False)
lines = len(importfile.readlines())
click.echo('Total Number of lines: %s' % lines)
importfile.seek(0) # Reset file pointer to the beginning
if click.confirm('Do you want to add these %s recipients to the <%s> mailing list?' % (lines, mlist)):
click.echo('OK, let\'s start subscribing...!')
while True:
recipient = importfile.readline().strip()
if not recipient:
break
click.echo('Adding <%s> to list %s...' % (recipient, mlist))
process = subprocess.Popen(['/usr/bin/mlmmj-sub', '-L', listhome + '/' + mlist, '-a', recipient,
# '-c' = send confirmation to sub, '-q' = don't notify owner
# '-f' = force (no sub-mod), '-s' = no mail if already sub
'-c', '-q', '-f', '-s'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = process.communicate()
if stdout:
click.echo(stdout)
if stderr:
click.echo(stderr)
click.echo('...job is DONE! :)')
else:
click.echo('OK, finished without action... :(')
if __name__ == '__main__':
importer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment