Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

read-github-notification 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/ruby
  2. #
  3. # read-github-notification -- prevent your notifications inbox on
  4. # github.com from filling up if you read github's email-based
  5. # notifications from a text-based MUA such as mutt.
  6. # Copyright (c) 2014 Adam Spiers <adam@spiers.net>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Background
  22. # ==========
  23. #
  24. # At the bottom of
  25. #
  26. # https://help.github.com/articles/configuring-notification-emails/
  27. #
  28. # it says:
  29. #
  30. # Shared read state
  31. # -----------------
  32. #
  33. # If you read a notification email, it'll automatically be marked as
  34. # read in the Notifications section. An invisible image is embedded
  35. # in each mail message to enable this, which means that you must
  36. # allow viewing images from notifications@github.com in order for
  37. # this feature to work.
  38. #
  39. # However this doesn't automatically work if you use a text-based MUA
  40. # such as mutt.
  41. #
  42. # Solution
  43. # ========
  44. #
  45. # mutt has a nice message-hook feature where you can execute mutt
  46. # functions for messages matching specific criteria. So we can use
  47. # that to pipe the whole email to this script whenever a message
  48. # is being read for the first time:
  49. #
  50. # message-hook "(~N|~O) ~f notifications@github.com" "push '<pipe-message>read-github-notification\n'"
  51. #
  52. # This script reads the email on STDIN (or from a filename argument),
  53. # extracts the URL of the 1-pixel read notification beacon <img>, and
  54. # sends an HTTP request for that image, so that github knows the
  55. # notification has been read.
  56. require 'net/http'
  57. abort "Maximum of one filename argument" if ARGV.length > 1
  58. BEACON_RE = %r!<img alt="" height="1" src="(https://github\.com/notifications/beacon/.+?\.gif)" width="1" />!
  59. ARGF.each do |line|
  60. if line =~ BEACON_RE
  61. uri = URI($1)
  62. response = Net::HTTP.get_response(uri)
  63. case response
  64. when Net::HTTPSuccess
  65. exit 0 # github should now know we read the notification
  66. else
  67. abort response.body
  68. end
  69. end
  70. end
  71. abort "Couldn't find notification beacon <img> URL"