The Joyent Community

A place where the Joyent community can gather, help each other out, and stay informed.

You are not logged in.

#1 2005-05-28 05:45:15

undees
Person With Descriptive Text Under User Name
From: Portland, OR
Registered: 2005-02-08
Posts: 19
Expertise

Receive an e-mailed iCal to a script

I applaud the decision to require SFTP only. However, I'll need to make an adjustment at my end to keep up. Our firewall at work does not admit SSH traffic, and our proxy is too primitive to understand WebDAV.

I need to get .ics files from my work PC to my TxD account on a regular basis.

Any suggestions?

The first idea that presents itself to me is to create a new alias in Webmin and select the "Feed to program" option. Does that choice mean I can just dump into my homedir an .rb file with the appropriate shebang inside it, parse out the .ics file from the e-mail, and save it in my ical directory? What does my script "see"? Is it the entire source of the mail in plain text? Does it come in on stdin?

Are there smarter alternatives to what I'm doing?

Thanks in advance for any ideas.

Offline

 

#2 2005-05-28 11:00:55

tim
The Apprentice
From: England
Registered: 2004-06-01
Posts: 333
Expertise

Re: Receive an e-mailed iCal to a script

undees wrote:

Does that choice mean I can just dump into my homedir an .rb file with the appropriate shebang inside it, parse out the .ics file from the e-mail, and save it in my ical directory?


You can!

Is it the entire source of the mail in plain text? Does it come in on stdin?


Yes and yes.


still on one

Offline

 

#3 2005-05-28 11:17:34

tim
The Apprentice
From: England
Registered: 2004-06-01
Posts: 333
Expertise

Re: Receive an e-mailed iCal to a script


still on one

Offline

 

#4 2005-05-28 15:42:23

schussat
Cold-cocking the drill sergeant.
From: Flagstaff
Registered: 2004-06-01
Posts: 2151
Website  Expertise

Re: Receive an e-mailed iCal to a script

- blink -
.
That's awesome.

Last edited by schussat (2005-05-28 15:43:14)

Offline

 

#5 2005-05-29 10:18:59

undees
Person With Descriptive Text Under User Name
From: Portland, OR
Registered: 2005-02-08
Posts: 19
Expertise

Re: Receive an e-mailed iCal to a script

Brilliant. Thanks, Tim.

The Ruby version will appear in a subsequent post (with TMail installed in my home dir -- happy to hear of any better way to do this).

Still a couple of file permission issues to work out: the file is created owned by nobody:username. The only way for it to be available by WebDAV appears to be to give the file o+r permissions (e.g., 664). What user does WebDAV run? Is there a way for me to make my calendar file available via WebDAV without allowing any TxD user on my server to be able to read the file?

Offline

 

#6 2005-05-29 10:21:34

undees
Person With Descriptive Text Under User Name
From: Portland, OR
Registered: 2005-02-08
Posts: 19
Expertise

Re: Receive an e-mailed iCal to a script

As promised, here's the Ruby version of the script.

Code:

#!/usr/local/bin/ruby
$: << '/home/username/usr/local/lib/ruby/site_ruby/1.8'
require 'tmail'

s = $stdin.read
mail = TMail::Mail.parse s
mail.parts.each do |part|

if 'text/calendar' == part.content_type t = part.body t.gsub!(/=[\r\n]+/, '') t.gsub!(/=(\w\w)/) {$1.hex.chr} outPath = '/home/username/path/to/Calendar.ics' File.open outPath, 'w' do |f| f.write t end File.chmod 0664, outPath end
end

Last edited by undees (2005-05-29 10:23:12)

Offline

 

#7 2005-05-29 18:29:49

jason
a chief (i started this place)
From: San Francisco
Registered: 2004-06-01
Posts: 8821
Website  Expertise

Re: Receive an e-mailed iCal to a script


Rock On!

Offline

 

#8 2005-05-29 18:32:58

jason
a chief (i started this place)
From: San Francisco
Registered: 2004-06-01
Posts: 8821
Website  Expertise

Re: Receive an e-mailed iCal to a script

undees wrote:

As promised, here's the Ruby version of the script.


The power of snippets:

http://textsnippets.com/tags/calendar/email

Offline

 

#9 2005-05-29 19:22:38

tim
The Apprentice
From: England
Registered: 2004-06-01
Posts: 333
Expertise

Re: Receive an e-mailed iCal to a script

Who couldn't see that coming? ;-)


still on one

Offline

 

#10 2005-05-30 02:16:51

undees
Person With Descriptive Text Under User Name
From: Portland, OR
Registered: 2005-02-08
Posts: 19
Expertise

Re: Receive an e-mailed iCal to a script

Thanks for posting the snippet, Jason! Good to know that I can post there in the future if an idea possesses me and might be of use to others.

Do you have any advice for the WebDAV / permissions thing?

My latest thought was to go ahead and let the mail-triggered script save the file with 660 permissions (owned by nobody:undees, which I don't think I can control), and maybe kick off a cron job to copy this file once a day to a file fully owned by me. If a file is owned by undees:undees, can I give it restrictive permissions (660) and still see it via WebDAV?

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson