Permalink
Browse files

Mailbox model wraps the machinery behind, generic mechanism to preren…

…der attributes on model's instances

* Mailbox model is the place to put all "find, download, and stock"
code for mails, to be able to easily use it via cue,
* generic mechanism of pre rendering prefixed attributes for models
(you only add _render_nameofattributetoprerender method),
* improved handling for mailbox management,
* a bit more info in the readme.
  • Loading branch information...
1 parent 57d5446 commit 2116dc4f56ddb08978f60b6e8f35c932686c62ab @seeker89 committed Aug 2, 2012
View
@@ -1,20 +1,51 @@
# Cozy Mail
-One of the first bunch of applications available on the platform - email client and aggregator.
+One of the first applications available on the platform - email client and aggregator.
-# So, what it does ?
+# How the idea was born ?
-Cozy Mail will let You configure all your mailboxes via smtp+imap,
-synchronise the content, and use all of them as one via a cozy web interface.
+Most of us have to cope with a handful of mailboxes every day - personal, professional, legacy one. Sometimes your boss forces you to use their solution, he paid so much for, so you click and open, and click..
+
+Moreover, at some point you realize you don't won your data anymore - it is all hosted somewhere, by a huge, nameless company.
+
+
+You'd like to have all your data in one place, choose this place, and become free ? And perhaps you'd also like this software to be reliable, well-supported, and ... open source ?
+
+You're right, grab your copy of CozyMail. It's free !
+
+
+
+# So, what does it do ?
+
+Cozy Mail will let You configure all your mailboxes via smtp+imap, synchronize the content (mail you marked as read will be visible in cozy as well as in your legacy mailbox, just in case), and use all of them as one via a cozy web interface.
+
+Yes, we paid much attention to make the interface easy to use, nice and lean.
+
+Future versions will allow a purchase of your own domain and remote backup in the background.
+
+
+
+# Well, great! So how it works ?
+
+Our stack includes node.js, mongodb, expressjs, railwayjs, backbone, stylus, jade and brunch to start with.
+
+A bunch of top technologies, becoming extremely popular due to their innovative nature... Well, the technology of tomorrow, one would say.
+
+
+
+
+
+
+# Authors
+
+At the moment the application is being developed by Mikolaj Pawlikowski (mikolaj.pawlikowski.pl)
-Future versions will allow a purchase of your own domain and remote backup
-in the background.
# About Cozy
Cozy Template is suited to be deployed on the Cozy platform. Cozy allow you to
-host all your personnal application in a single place you control.
+host all your personal application in a single place you control.
You can manage efficiently your data while protecting your privacy.
You will find more on our website : http://www.mycozycloud.com
View
@@ -1,14 +1,18 @@
Mailbox.checkAllMailboxes = ->
Mailbox.all (err, mbs) ->
for mb in mbs
- Mailbox.getMail(mb)
+ mb.getNewMail
-Mailbox.getMail = (mailbox) ->
-
+Mailbox.prototype.getNewMail = ->
+ @getMail ["ALL", ['SINCE', 'July 1, 2012']]
+
+
+Mailbox.prototype.getMail = (constraints) ->
## dependences
imap = require "imap"
mailparser = require "mailparser"
-
+
+ mailbox = this
console.log "getMail of mailbox: " + JSON.stringify(mailbox)
#
@@ -31,7 +35,7 @@ Mailbox.getMail = (mailbox) ->
# open or die
exitOnErr err if err
- server.search ["ALL", ['SINCE', 'July 25, 2012']], (err, results) =>
+ server.search constraints, (err, results) =>
exitOnErr err if err
unless results.length
@@ -45,14 +49,29 @@ Mailbox.getMail = (mailbox) ->
headers: false
fetch.on "message", (message) ->
- fds = {}
- filenames = {}
parser = new mailparser.MailParser
- parser.on "end", (mail) =>
- console.log "About to create a new mail: " + JSON.stringify(mail)
+ parser.on "end", (m) =>
+ # console.log "About to create a new mail:\n" + JSON.stringify(m)
+ mail =
+ date: new Date(m.headers.date).toJSON()
+ createdAt: new Date().toJSON()
+
+ from: JSON.stringify m.from
+ to: JSON.stringify m.to
+ subject: m.subject
+ priority: m.priority
+
+ text: m.text
+ html: m.html
+
+ headers_raw: JSON.stringify m.headers
+ raw: JSON.stringify m
+
+ # id_remote_mailbox: m.headers.getAttribute("message-id")
+
mailbox.mails.create mail, (err, mail) ->
- console.log "New mail created: " + JSON.stringify(mail)
+ console.log "New mail created:\n" + JSON.stringify(mail)
message.on "data", (data) ->
parser.write data.toString()
@@ -11,11 +11,16 @@ class exports.MailsCollection extends Backbone.Collection
model: Mail
url: 'mails/'
- comparator: (mail) ->
- mail.get("date")
+ comparator: (a, b) ->
+ if a.get("date") > b.get("date")
+ -1
+ else if a.get("date") == b.get("date")
+ 0
+ else
+ 1
initialize: ->
@on "change_active_mail", @navigateMail, @
navigateMail: (event) ->
- window.app.router.navigate "mail:" + @activeMail.id
+ window.app.router.navigate "mail/" + @activeMail.id
@@ -15,4 +15,16 @@ class exports.Mail extends BaseModel
@view.remove() if @view?
redrawView: ->
- @view.render() if @view?
+ @prerender()
+ @view.render() if @view?
+
+###
+ PRERENDERING
+###
+
+ _render_from: (from) ->
+ parsed = JSON.parse(from)
+ out = ""
+ for addr, name in parsed
+ out + name + ", "
+ out
@@ -5,6 +5,32 @@
###
class exports.BaseModel extends Backbone.Model
+
+ debug : true
isNew: () ->
- not @id?
+ not @id?
+
+ prerender: () ->
+ console.log "Prerender" if @debug?
+ for prop, val of @attributes
+ if @["_render_" + prop]?
+ console.log "rendering " + prop + " -> __" + prop if @debug?
+ @attributes["__" + prop] = @["_render_" + prop] (val)
+ else
+ console.log "copying " + prop + " -> __" + prop if @debug?
+ @attributes["__" + prop] = @attributes[prop]
+ console.log @ if @debug?
+ @
+
+
+ _render_from: (from) ->
+ parsed = JSON.parse(from)
+ out = ""
+ for obj in parsed
+ out += obj.name + " <" + obj.address + "> "
+ out
+
+ _render_date: (date) ->
+ parsed = new Date date
+ parsed.toUTCString()
@@ -9,6 +9,10 @@ class exports.MainRouter extends Backbone.Router
'' : 'home'
'config-mailboxes' : 'configMailboxes'
+ # routes that need regexp.
+ initialize: ->
+ @route(/^mail\/(.*?)$/, 'mail')
+
################################################################
############## INDEX
home : ->
@@ -22,4 +26,14 @@ class exports.MainRouter extends Backbone.Router
configMailboxes : ->
app.appView.render()
app.appView.set_layout_mailboxes()
-
+
+
+################################################################
+############## INDEX
+ mail : (path) ->
+ app.appView.render()
+ app.appView.set_layout_mails()
+
+ if app.mails.get(path)?
+ app.mails.activeMail = app.mails.get(path)
+ app.mails.trigger "change_active_mail"
@@ -18,6 +18,9 @@ class exports.AppView extends Backbone.View
constructor: ->
super()
+ tick = (event) =>
+ window.app.mails.fetch({add : true})
+ @timer = window.setInterval tick, 5000
render: ->
# put on the big layout
@@ -12,6 +12,8 @@ class exports.MailsElement extends Backbone.View
@collection.on "change_active_mail", @render, @
render: ->
+ @collection.activeMail.prerender()
template = require('./templates/_mail/mail_big')
- $(@el).html template("model" : @collection.activeMail?.toJSON())
+ $(@el).html template("model" : @collection.activeMail.toJSON())
+ @.$("#mail_content").html @.$("#mail_content").text()
@
@@ -23,6 +23,7 @@ class exports.MailsListElement extends Backbone.View
@collection.trigger "change_active_mail"
render: ->
+ @model.prerender()
template = require('./templates/_mail/mail_list')
$(@el).html template({"model" : @model.toJSON(), "active" : @model == @collection.activeMail})
@
@@ -1,10 +1,15 @@
.well
p
- | #{model.from}
- i(style='color: lightgray;') #{model.date}
- h4 #{model.subject}
- div.
- #{model.html}
+ | #{model.__from}
+ i(style='color: lightgray;') #{model.__date}
+ h3 #{model.__subject}
+ br
+ div#mail_content
+ if model.__html
+ #{model.__html}
+ else
+ #{model.__text}
+
.btn-toolbar
.btn-group
a.btn.btn-primary
@@ -1,20 +1,20 @@
if active
td
p
- | #{model.from}
+ | #{model.__from}
br
- i(style='color: lightgray;') #{model.date}
- p #{model.subject}
- td
- a.btn.btn-mini.choose_mail_button
- i.icon-arrow-right
+ i(style='color: lightgray;') #{model.__date}
+ p #{model.__subject}
+ td
+ a.btn.btn-mini.choose_mail_button
+ i.icon-arrow-right
else
td
p
- | #{model.from}
+ | #{model.__from}
br
- i(style='color: lightgray;') #{model.date}
- p #{model.subject}
+ i(style='color: lightgray;') #{model.__date}
+ p #{model.__subject}
td
- a.btn.btn-mini.choose_mail_button
- i.icon-arrow-right
+ a.btn.btn-mini.choose_mail_button
+ i.icon-arrow-right
Oops, something went wrong.

0 comments on commit 2116dc4

Please sign in to comment.