This is a post I sent to my blog via email. I know there are lots of blog clients out there, but a email editor I think would work just as good.
I will post a few more with this to test it out more.
Ok, so I did post this with my cell phone email client, but I then came to the computer to finish it up so I could include the code sample.
I basically took the xmlrpc section from BlogCFC and made an email responder that checks for new email and it builds a blog post from those emails.
Here is the code which I have set as a scheduled task. There is a lot going on here, so ill explain it after:
2 <cfquery name="qHeader" dbtype="query">
3 SELECT uid,[from],[date]
4 FROM qHeader2
5 WHERE [from] = 'youremail@server.com'
6 ORDER BY messagenumber ASC
7 </cfquery>
8
9 <cfif qHeader.RecordCount>
10 <cfpop action="getall" name="qMessage" server="mail.server" username="user" password="pass" uid="#ValueList( qHeader.uid )#"
11 attachmentpath="#tempDir#"/>
12
13 <cfset att = arrayNew(1)>
14 <cfset p = structNew()>
15
16 <cfloop query="qMessage">
17 <!---first lets handle the image attachments if any--->
18 <cfif Len(qMessage.attachments)>
19 <cfloop list="#StructKeyList(qMessage.CIDS)#" index="I">
20 <cfset ns = structNew()>
21 <cfset tmp = replace(qMessage.CIDS[i],"<","","ALL")>
22 <cfset tmp = replace(tmp,">","","ALL")>
23 <cfset newName = hash(listFirst(i,"."), "md5") & "." & listlast(i, ".") />
24 <cfset ns.old = i><cfset ns.new = newName><cfset ns.cid = tmp>
25 <cfset arrayAppend(att,ns)>
26 </cfloop>
27 </cfif>
28 <!--- next our actual message for the blog entry.
29 I am using the subject line to hold variables delimited with a ~ --->
30 <cfset p.body = qMessage.body>
31 <cfset p.cats = ListGetAt(qMessage.subject,1,"~")>
32 <cfset p.subject = listGetAt(qMessage.subject,2"~")>
33 <cfset p.released = listGetAt(qMessage.subject,3"~")>
34 <cfset p.sendemail = listGetAt(qMessage.subject,4"~")>
35
36 <cfif arrayLen(att)>
37 <cfset p.body = replaceNoCase(p.body,"cid:","","ALL")>
38 <cfset u = "../../enclosures/">
39 <cfloop from="1" to="#ArrayLen(att)#" index="I">
40 <cfset p.body = ReplaceNoCase(p.body,att[i].cid,u & att[i].new,"ALL")>
41 </cfloop>
42 </cfif>
43
44
45
46 <!--- now we will use the xmlrpc service that is already in place to send our blog entry into blogcfc --->
47 <cfset xmlrpc = createObject("component","xmlrpc.xmlrpc")>
48 <cfset entry = structNew()>
49 <cfset entry.title = p.subject>
50 <cfset entry.body = htmleditformat(p.body)>
51 <!---<cfset application.body = htmleditformat(p.body)>
52 TODO: Handle <more/> --->
53
54 <!---// replace the ellipse character with the HTML entity //--->
55 <cfset entry.body = replace(entry.body, chr(8230), "&##8230;", "all") />
56 <!---// replace the em dash character with the HTML entity //--->
57 <cfset entry.body = replace(entry.body, chr(8212), "&##8212;", "all") />
58 <cfset entry.body = replace(entry.body, chr(151), "&##8212;", "all") />
59 <cfset entry.body = replace(entry.body, "--", "&##8212;", "all") />
60 <cfset entry.body = replace(entry.body, chr(8211), "&##8211;", "all") />
61 <cfset entry.body = replace(entry.body, chr(150), "&##8211;", "all") />
62 <cfset entry.body = replace(entry.body, "", "&##8211;", "all") />
63 <cfset entry.body = xmlrpc.unescapeMarkup(entry.body) />
64 <!--- Handle potential <more/> --->
65 <!--- fix by Andrew --->
66 <cfset strMoreTag = "<more/>">
67 <cfset moreStart = findNoCase(strMoreTag,entry.body)>
68 <cfif moreStart gt 1>
69 <cfset moreText = trim(mid(entry.body,(moreStart+len(strMoreTag)),len(entry.body)))>
70 <cfset entry.body = trim(left(entry.body,moreStart-1))>
71 <cfelse>
72 <cfset moreText = "">
73 </cfif>
74
75 <cfset entry.morebody = moretext>
76 <cfset entry.posted = now() />
77 <cfset entry.allowcomments = true>
78
79 <cfset entry.enclosure = "" />
80 <cfset entry.filesize = 0 />
81 <cfset entry.mimetype = "" />
82 <cfset entry.released = p.released/>
83
84 <cfset entry.sendemail = p.sendemail>
85 <cfset entry.alias = application.blog.makeTitle(entry.title)>
86
87<!--- next log into blogcfc and post our entry --->
88 <cfloginuser name="#variables.username#" password="#variables.password#" roles="admin">
89
90 <cfinvoke component="#application.blog#" method="addEntry" returnVariable="newid">
91 <cfloop item="key" collection="#entry#">
92 <cfinvokeargument name="#key#" value="#entry[key]#">
93 </cfloop>
94 </cfinvoke>
95 <cfset entryid = newid>
96 <cfset result = newid>
97
98 <!--- associate a category if exists --->
99 <cfset catlist = "">
100 <cfif structKeyExists(p, "cats")>
101 <cfloop index="x" list="#p.cats#">
102 <cfset catid = translateCategory(x)>
103 <cfif isValid("UUID",catid)>
104 <cfset catlist = listAppend(catlist, catid)>
105 </cfif>
106 </cfloop>
107 <cfelse>
108 <cfset catlist = "41C1CEA9-C0F7-B0AE-D24BE7399F23ED8B">
109 </cfif>
110
111 <cfif len(catlist)>
112 <cfset application.blog.assignCategories(entryid, catlist)>
113 </cfif>
114
115 <!--- clear cache --->
116 <cfmodule template="../tags/scopecache.cfm" scope="application" clearall="true">
117
118
119
120
121 </cfloop>
122
123 <cfpop action="delete" server="mail.server" username="user" password="pass" uid="#ValueList( qHeader.uid )#"/>
124
125 <!--- mail yourself a copy just in case???
126 <cfmail to="you" from="blog" subject="ePost" type="html">
127 #now()#<BR>
128 #m#<BR>
129 <cfdump var="#qHeader#" label="mail">
130 </cfmail>--->
131
132 </cfif>
Lots going on here. its a big chunk of code. First it gets a list of emails that were sent BY YOU! to the specified blog email box. Next loop over those and builds out a struct with our vars to send into BlogCFC to build our post. Then at the end it deletes the email and sends you a copy if you want it.
So there you have it, a simple way to post a blog entry from a phone or any other email client.
Let me know if there is a better way to handle this, I would love to see it.