forked from max-mapper/couchmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·70 lines (64 loc) · 2.22 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var couchapp = require('couchapp')
, path = require('path')
;
ddoc =
{ _id:'_design/couchmail'
, rewrites:
[ {from:"/", to:'index.html'}
, {from:"cache.manifest", to:'_show/cache'}
, {from:"favicon.png", to:'favicon.ico'}
, {from:"/api/mail_search", to:"../../../_search/couch-user-mail/couch-user-mail/_search"} // elasticsearch
, {from:"/api/irc_search", to:"../../../_search/couch-irc-logs/couch-irc-logs/_search"} // elasticsearch
, {from:"/api/irc", to:'../../../couch-irc-logs/'}
, {from:"/api/mail", to:'../../../couch-user-mail/'}
, {from:"/api/irc/*", to:'../../../couch-irc-logs/*'}
, {from:"/api/mail/*", to:'../../../couch-user-mail/*'}
, {from:"/api", to:'../../'}
, {from:"/api/*", to:'../../*'}
, {from:"/*", to:'*'}
]
, shows: {
cache: function(head, req) {
var manifest = "";
for (var a in this._attachments) {
manifest += ("/" + a + "\n");
}
var r =
{ "headers": { "Content-Type": "text/cache-manifest"}
, "body": "CACHE MANIFEST\n" + manifest
}
return r;
}
}
}
;
ddoc.views = {
by_date: {
map: function(doc) {
if (doc.headers && doc.headers.date) {
var date = JSON.stringify(new Date(doc.headers.date[0]));
var message = {
subject: doc.headers.subject[0],
date: date,
body: doc.bodytext,
from: doc.headers.from[0]
}
if (doc.parts && doc.parts.length > 0) {
for (var i = 0; i < doc.parts.length; i++) {
if (JSON.stringify(doc.parts[i].headers).match("text/html")) message.body = doc.parts[i].bodytext;
}
}
if (doc.headers['message-id']) message.messageId = doc.headers['message-id'][0];
if (doc.headers.references) message.references = doc.headers.references[0];
emit(date, message);
}
}
}
};
ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {
if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {
throw "Only admin can delete documents on this database.";
}
}
couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));
module.exports = ddoc;