From 05695c12ea2d18256378fca041d5bed2f0350145 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 28 Jun 2012 16:51:46 +0200 Subject: [PATCH] Enable the message_gateway to handle sending all email to a specific user. The current scanning on to: and from: fields does not work if you bcc Tracks in email. site.yml.tmpl is updated to reflect this and removes cas, ldap and openid configs Also the integrations page is updated to reflect the above --- app/models/message_gateway.rb | 20 ++++++++++++------- app/views/integrations/index.de.html.erb | 14 +++++++++---- app/views/integrations/index.en.html.erb | 8 +++++++- app/views/integrations/index.nl.html.erb | 8 +++++++- config/site.yml.tmpl | 25 +++++++----------------- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/models/message_gateway.rb b/app/models/message_gateway.rb index e3a4adc8..eaea3818 100644 --- a/app/models/message_gateway.rb +++ b/app/models/message_gateway.rb @@ -23,11 +23,9 @@ class MessageGateway < ActionMailer::Base end end - # stupid T-Mobile often sends the same message multiple times - return if user.todos.where(:description => description).first - todo = Todo.from_rich_message(user, context.id, description, notes) todo.save! + Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}" end private @@ -37,10 +35,18 @@ class MessageGateway < ActionMailer::Base end def get_user_from_email_address(email) - address = get_address(email) - user = User.where("preferences.sms_email" => address.strip).includes(:preference).first - if user.nil? - user = User.where("preferences.sms_email" => address.strip[1.100]).includes(:preference).first + if SITE_CONFIG['email_dispatch'] == 'single_user' + Rails.logger.info "All received email goes to #{ENV['TRACKS_MAIL_RECEIVER']}" + user = User.find_by_login(ENV['TRACKS_MAIL_RECEIVER']) + Rails.logger.info "WARNING: Unknown user set for TRACKS_MAIL_RECEIVER (#{ENV['TRACKS_MAIL_RECEIVER']})" if user.nil? + else + address = get_address(email) + Rails.logger.info "Looking for user with email #{address}" + user = User.where("preferences.sms_email" => address.strip).includes(:preference).first + if user.nil? + user = User.where("preferences.sms_email" => address.strip[1.100]).includes(:preference).first + end + Rails.logger.info(!user.nil? ? "Email belongs to #{user.login}" : "User unknown") end return user end diff --git a/app/views/integrations/index.de.html.erb b/app/views/integrations/index.de.html.erb index 3f701411..04850541 100644 --- a/app/views/integrations/index.de.html.erb +++ b/app/views/integrations/index.de.html.erb @@ -100,18 +100,24 @@ If Tracks is running on the same server as your mail server, you can use the integrated mail handler built into tracks. Steps to set it up:

You can also use the Rich Todo API to send in tasks like "do laundry @ Home" or "Call Bill > project X". The subject of the message will fill description, context, and project, while the body will populate the tasks's note.

+

+ You may need to configure your site.yml to tell the message gateway to look at the to: field or from: field to + lookup Tracks' user from the email address in that field.

+

You can also send all email to a specific Tracks user. Configure mail_dispatch in site.yml to single_user and pass the login of the user: +

TRACKS_MAIL_RECEIVER=<%=current_user.login%> usr/bin/bundle exec /PATH/TO/TRACKS/script/rails r -e production 'MessageGateway.receive(STDIN.read)'
+

Add Tracks as a Google Gmail gadget

diff --git a/app/views/integrations/index.en.html.erb b/app/views/integrations/index.en.html.erb index 9ffbb5f0..791133c7 100644 --- a/app/views/integrations/index.en.html.erb +++ b/app/views/integrations/index.en.html.erb @@ -105,13 +105,19 @@ "<%= Preference.human_attribute_name('sms_context') %>" for todos sent in via email (which could come from an SMS message)
  • In sendmail/qmail/postfix/whatever, set up an email address - alias to pipe messages to
    /PATH/TO/RUBY/ruby /PATH/TO/TRACKS/script/runner -e production 'MessageGateway.receive(STDIN.read)'
  • + alias to pipe messages to
    /usr/bin/bundle exec /PATH/TO/TRACKS/script/rails r -e production 'MessageGateway.receive(STDIN.read)'
  • Send an email to your newly configured address!
  • You can also use the Rich Todo API to send in tasks like "do laundry @ Home" or "Call Bill > project X". The subject of the message will fill description, context, and project, while the body will populate the tasks's note.

    +

    + You may need to configure your site.yml to tell the message gateway to look at the to: field or from: field to + lookup Tracks' user from the email address in that field.

    +

    You can also send all email to a specific Tracks user. Configure mail_dispatch in site.yml to single_user and pass the login of the user: +

    TRACKS_MAIL_RECEIVER=<%=current_user.login%> usr/bin/bundle exec /PATH/TO/TRACKS/script/rails r -e production 'MessageGateway.receive(STDIN.read)'
    +

    Add Tracks as a Google Gmail gadget

    diff --git a/app/views/integrations/index.nl.html.erb b/app/views/integrations/index.nl.html.erb index 3eac8df1..aaf6abcb 100644 --- a/app/views/integrations/index.nl.html.erb +++ b/app/views/integrations/index.nl.html.erb @@ -109,13 +109,19 @@ verzonden zijn via email (die bijv. komen via een SMS message)
  • In sendmail/qmail/postfix/whatever, stel een email address alias in om berichten door te sturen naar -
    /PATH/TO/RUBY/ruby /PATH/TO/TRACKS/script/runner -e production 'MessageGateway.receive(STDIN.read)'
  • +
    /usr/bin/bundle exec /PATH/TO/TRACKS/script/rails r -e production 'MessageGateway.receive(STDIN.read)'
  • Verstuur een email naar het net geconfigureerde e-mail adres!
  • Je kan ook de Rich Todo API gebruiken om acties te maken zoals "do laundry @ Home" of "Call Bill > project X". Het onderwerp van het bericht zal de bijschrijving van de actie vullen, de context, en het project, terwijl de body van het bericht de notities van de actie zal vullen.

    +

    + Het kan nodig zijn om jouw site.yml te configureren om de message gateway te laten kijken naar het to: veld of het from: veld om + de Tracks-gebruiker op te zoeken met het emailadres uit dat veld.

    +

    Je kan ook alle email naar een specifieke Tracks gebruiker sturen. Stel mail_dispatch in site.yml in op single_user en geeft de login van de gebruiker door: +

    TRACKS_MAIL_RECEIVER=<%=current_user.login%> usr/bin/bundle exec /PATH/TO/TRACKS/script/rails r -e production 'MessageGateway.receive(STDIN.read)'
    +

    Voeg tracks toe als een Google Gmail gadget

    diff --git a/config/site.yml.tmpl b/config/site.yml.tmpl index a88c224d..c188e6c1 100644 --- a/config/site.yml.tmpl +++ b/config/site.yml.tmpl @@ -3,25 +3,15 @@ salt: "change-me" -# Uncomment ldap or open_id if you want to use those authentication schemes. -# If you choose ldap, see the additional configuration options further down. -# NOTE: openid is not supported anymore. +# NOTE: openid, ldap and cas are currently not supported anymore. authentication_schemes: - "database" - # - "ldap" - # - "cas" #set the prefered authentication scheme to display first on the login page #prefered_auth: database -# Uncomment if using cas -#cas_server: "https://cas.demo.edu/cas" -#cas_server_logout: "https://cas.demo.edu/cas/logout" - - - # You''ll probably want to change this to the time zone of the computer where Tracks is running # run rake time:zones:local have Rails suggest time zone names on your system time_zone: "UTC" @@ -35,22 +25,21 @@ secure_cookies: false # rather than the From: address. # email_dispatch: 'to' +# If you want to send all email to a specific user, uncomment the following line and +# set the environment variable TRACKS_MAIL_RECEIVER to the login name of the user that +# will receive all email +# email_dispatch: 'single_user' + # Set this to the subdirectory you're hosting tracks in and uncomment if applicable # NOTE: you will also need to set up your web server to deal with the relative # URL. Mongrel, for example, has a --prefix option. # subdir: "/tracks" + # Set to true to allow anyone to sign up for a username. open_signups: false -# Only needed if ldap is included in authentication_schemes -# ldap: -# library: 'net/ldap' -# servers: -# - 'localhost' -# use_ssl: false -# login_format: 'cn=%s,dc=example,dc=com' # When integrating your tracks instance with http://cloudmailin.com/ by using the /integrations/cloudmailin URL, # this value is the cloudmailin-secret for verifying the authenticity of the request.