Skip to content

Commit

Permalink
offer to set sendmail command instead of guessing
Browse files Browse the repository at this point in the history
this addresses #17

also, the sendmail command may contain an equal sign `=`, for example to set an account using msmtp (for users using more than one email account), so rather split using the full `sendmail=` string marking the beginning of the sendmail command
  • Loading branch information
Konfekt committed Jan 11, 2024
1 parent cba522e commit fceb557
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mutt-ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-t tentatively accept
(accept is default, last one wins)
-D display only
-S <sendmail command>
""" % sys.argv[0]

def del_if_present(dic, key):
Expand Down Expand Up @@ -146,7 +147,7 @@ def display(ical):

def sendmail():
mutt_setting = subprocess.check_output(["mutt", "-Q", "sendmail"])
return mutt_setting.strip().decode().split("=")[1].replace('"', '').split()
return mutt_setting.strip().decode().split('sendmail=')[1].replace('"', '').split()

def organizer(ical):
if 'organizer' in ical.vevent.contents:
Expand All @@ -158,9 +159,10 @@ def organizer(ical):
raise("no organizer in event")

if __name__=="__main__":
sendmail = None
email_address = None
accept_decline = 'ACCEPTED'
opts, args=getopt(sys.argv[1:],"e:aidtD")
opts, args=getopt(sys.argv[1:],"S:e:aidtD")

if len(args) < 1:
sys.stderr.write(usage)
Expand All @@ -172,6 +174,8 @@ def organizer(ical):
for opt,arg in opts:
if opt == '-D':
sys.exit(0)
if opt == '-S':
sendmail = arg.split()
if opt == '-e':
email_address = arg
if opt == '-i':
Expand Down Expand Up @@ -220,5 +224,6 @@ def organizer(ical):
message.add_alternative(ans.serialize(),
subtype='calendar',
params={ 'method': 'REPLY' })

execute(sendmail() + ['--', to], message.as_bytes())
if not sendmail:
sendmail = sendmail()
execute(sendmail + ['--', to], message.as_bytes())

0 comments on commit fceb557

Please sign in to comment.