Premshree Pillai ([info]premshree) wrote,
@ 2004-08-02 18:26:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Reblet, anyone?
I just coded an SMS to LiveJournal gateway in REBOL. I think I should start using it more often.
REBOL [
	Title:  "SMS2LJ"
	Date:   2-Feb-2000
	File:   %sms2lj.r
	Version: 1.0.0

	Author: "Premshree Pillai"
	Home:	"http://premshree.org/"
	Rights:  "Copyright (C) Premshree Pillai 2004"

	Purpose: {
		Post to your LiveJournal account by sending
		an SMS to your POP3 account ... using a service
		like Yahoo! Mail for SMS.
        }
]

comment [LiveJournal config]
LJ_USER: 	"*****"
LJ_PASSWORD: 	"*****"
JOURNAL: 	"*****"

comment [POP3 config]
POP3_HOST: 	"*****"
POP3_USER: 	"*****"
POP3_PASS: 	"*****"


postEvent: func [user password event subject journal] [
	date_time: probe parse to-string now {:}
	year: now/year
	month: now/month
	day: now/day
	hour: second probe parse first date_time {/}
	min: second date_time

	sms_post: rejoin [
		"mode=" "postevent"
		"&user=" user
		"&password=" password
		"&event=" event
		"&lineendings=" "pc"
		"&subject=" subject
		"&year=" year
		"&mon=" month
		"&day=" day
		"&hour=" hour
		"&min=" min
		"&usejournal=" journal
	]

	send_output: read/custom
	http://www.livejournal.com/interface/flat/ reduce [
		'POST sms_post
	]
]

getMails: func [host user password] [
	url: append append append append append "pop://" user ":" password "@" host
	print url
	inbox: open to-url url
	forall inbox [
		mail: import-email message: first inbox
		if equal? mail/subject "[none]" [
			body: probe parse mail/content none
			replace body newline " "
			postEvent LJ_USER LJ_PASSWORD body "" JOURNAL
		]
	]
	remove inbox
	clear inbox
	close inbox
]

forever [
	getMails POP3_HOST POP3_USER POP3_PASS
]


(Post a new comment)


[info]mannu
2004-08-02 07:15 am UTC (link)
Dude, you're doing good!

(Reply to this)(Thread)


(Anonymous)
2004-08-03 12:05 am UTC (link)
you never heard of rebol. how do you know hes doin good?

(Reply to this)(Parent)


[info]stillcarl
2004-08-03 02:37 am UTC (link)
Don't listen to that anonymous person. I've heard of REBOL and he is doing good! (I think:)

(Reply to this)(Parent)(Thread)


[info]mannu
2004-08-03 10:10 am UTC (link)
Well, how does the anonymous coward know I've never heard of REBOL? ;)

Anyway, I was referring to premshree's playing with new languages, not about the actual code above (I don't understand it).

(Reply to this)(Parent)


[info]stillcarl
2004-08-03 02:57 am UTC (link)
I think I should start using it more often.

Yes, I think so. It looks nice and tidy code, though I don't understand it, not knowning anything about SMS or Yahoo's mail or LJ's mail-linkup.

Hopefully I'll find the time to have a play with it someday. I have a mobile and I have a yahoo account (which I guess gives me Yahoo email too) and I have a site I could run your script on, so it's just possible I might get it working...

(Reply to this)(Thread)


[info]premshree
2004-08-03 03:34 am UTC (link)
The program, as it is, has nothing to do with SMSes. Basically, you need any mobile service—SMS or whatever—in order to send mails to your POP3 account.

The script polls your account continually ... and whenever a new mail arrives, posts the body of the mail to your LiveJournal account.

(Reply to this)(Parent)(Thread)


[info]stillcarl
2004-08-03 05:43 am UTC (link)
I've had a bath since I made that post and realised you wouldn't be using LJ's email service as, well, there wouldn't be much point given someone could send directly to it. :)

I've just tested my mobile's email sending and it was respectably fast - unlike when it first came online and the emails took half a day to arrive.

So, going by what you've said, I could just send directly to my server's POP account - I wouldn't need to go through Yahoo or similar? Thinking about it, it's obvious you could do this. You've really tempted me now. ;-)

The script polls your account continually

I wondered about that. Shouldn't there be a wait in the loop, or is it safe to be polling that often?

(Reply to this)(Parent)(Thread)


[info]premshree
2004-08-03 06:11 am UTC (link)
Only paid users can make use of LJ's post-by-email feature; that leaves non-paid users with the option of sending via LJ's SMS gateway ... but that, if I am correct, adds a line to the post, which many may not like. So basically this SMS2LJ gateway would be useful to non-paid LJ users who want to post via a mobile device.

... I wouldn't need to go through Yahoo or similar ...
No, you don't need to go through Yahoo!. You just need a way to send a mail to your account using a mobile device.

Shouldn't there be a wait in the loop, or is it safe to be polling that often?
Yes, there should be a wait call within the forever block. I forgot about that.

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…