Created
June 22, 2016 07:06
-
-
Save Glutexo/52200adf81e02ba1d119a9798f00ff9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Reads a mail from stdin, saves it to a new timestamped file and raises | |
# an macOS system notification. Can be used with PHP by entering this | |
# scripts path as a sendmail_path PHP INI variable. If used this way, | |
# from a webserver PHP instalation, make sure that the _www user has | |
# sufficent rights to execute the script and to write to the DIR_PATH | |
# folder. Also note that Dir.home returns the current user’s homedir. | |
# That means that if run by _www, it would return /Library/WebServer. | |
# | |
# Requires mail and terminal-notifier gems to be installed. | |
require 'date' | |
require 'mail' | |
require 'terminal-notifier' | |
DIR_PATH = File.join Dir.home, 'tmp', 'sendmail' | |
FILE_PATH = File.join DIR_PATH, | |
"#{DateTime.now.strftime '%Y-%m-%d %H:%M:%S.%L'}.eml" | |
stdin = $<.read | |
File.new(FILE_PATH, 'w') << stdin | |
mail = Mail.read_from_string stdin | |
TerminalNotifier.notify mail.subject, | |
title: 'sendmail', | |
subtitle: "To: #{mail.to.first}", | |
open: "file://#{FILE_PATH}", | |
sender: 'com.apple.Mail' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment