-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailing list ARChive.js
123 lines (108 loc) · 2.88 KB
/
Mailing list ARChive.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
"translatorID": "6d85fd99-35ce-46d2-9f1d-6c6a0d40d455",
"label": "MARC - Mailing list ARChive",
"creator": "Gabriel Alcaras",
"target": "https?://marc.info",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "g",
"lastUpdated": "2017-01-26 15:27:07"
}
/* global Zotero, ZU */
// eslint-disable-next-line no-unused-vars
function detectWeb (doc, url) {
var msgId = ZU.xpathText(doc, '//font/text()')
if (msgId !== null && msgId.indexOf('Message-ID: ')) {
return 'email'
}
}
// eslint-disable-next-line no-unused-vars
function doWeb (doc, url) {
var email = new Zotero.Item('email')
var metadata = ZU.xpathText(doc, '//font').split('\n')
/* Elements extraction */
var listTxt = metadata[1]
var subTxt = metadata[2]
var fromTxt = metadata[3]
var dateTxt = metadata[4]
/* Name Extraction */
var namePattern = new RegExp(/:\s+"?([^"]*)"?\s</)
var authorName = namePattern.exec(fromTxt)[1]
/* Date Extraction */
var datePattern = new RegExp(/:\s+(\d{4}-\d{2}-\d{2})/)
var sentDate = datePattern.exec(dateTxt)[1]
/* Title Extraction */
var titlePattern = new RegExp(/:\s+(.*)/)
var title = titlePattern.exec(subTxt)[1]
email.title = title
/* List Extraction */
var listPattern = new RegExp(/:\s+(.*)/)
var list = listPattern.exec(listTxt)[1]
/* Capitalize list name */
list = list.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); })
email.shortTitle = list + ' - Mailing list ARChives'
email.creators.push(ZU.cleanAuthor(authorName, 'author'))
email.date = sentDate
email.language = 'en'
email.accessDate = 'CURRENT_TIMESTAMP'
email.libraryCatalog = email.shortTitle
email.url = url
email.complete()
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://marc.info/?l=linux-kernel&m=87602757922179&w=2",
"items": [
{
"itemType": "email",
"subject": "Mutt && the list",
"creators": [
{
"firstName": "Aaron",
"lastName": "Tiensivu",
"creatorType": "author"
}
],
"date": "1997-08-29",
"language": "en",
"shortTitle": "Linux-kernel - Mailing list ARChives",
"url": "http://marc.info/?l=linux-kernel&m=87602757922179&w=2",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://marc.info/?l=git&m=116233880601299&w=2",
"items": [
{
"itemType": "email",
"subject": "Re: [PATCH] make git-push a bit more verbose",
"creators": [
{
"firstName": "Junio C.",
"lastName": "Hamano",
"creatorType": "author"
}
],
"date": "2006-10-31",
"language": "en",
"shortTitle": "Git - Mailing list ARChives",
"url": "http://marc.info/?l=git&m=116233880601299&w=2",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/