回答編集履歴
1
a
test
CHANGED
@@ -4,23 +4,29 @@
|
|
4
4
|
|
5
5
|
```javascript
|
6
6
|
|
7
|
-
function q219571(){
|
7
|
+
function q219571() {
|
8
8
|
|
9
9
|
const mailQuery = 'subject:お問い合わせ';
|
10
10
|
|
11
11
|
const threads = GmailApp.search(mailQuery);
|
12
12
|
|
13
|
-
const messages = GmailApp.getMessagesForThreads(threads).reduce(function (a,c) {
|
13
|
+
const messages = GmailApp.getMessagesForThreads(threads).reduce(function (a, c) {
|
14
|
+
|
15
|
+
return a.concat(c.map(mailToArray))
|
16
|
+
|
17
|
+
}, []);
|
14
18
|
|
15
19
|
const sheet = SpreadsheetApp.getActiveSheet();
|
16
20
|
|
17
21
|
const r = sheet.getLastRow();
|
18
22
|
|
19
|
-
sheet.getRange(r+1, 1
|
23
|
+
sheet.getRange(r + 1, 1, messages.length, 3).setValues(messages);
|
20
24
|
|
21
25
|
|
22
26
|
|
23
27
|
}
|
28
|
+
|
29
|
+
|
24
30
|
|
25
31
|
function messageToArray(m) {
|
26
32
|
|
@@ -28,23 +34,23 @@
|
|
28
34
|
|
29
35
|
return [
|
30
36
|
|
31
|
-
fetchData(body, '【 お名前 】'
|
37
|
+
fetchDataInSplit(body, '【 お名前 】'),
|
32
38
|
|
33
|
-
fetchData(body, '【 メールアドレス 】'
|
39
|
+
fetchDataInSplit(body, '【 メールアドレス 】'),
|
34
40
|
|
35
|
-
fetchData(body, '【 電話番号 】'
|
41
|
+
fetchDataInSplit(body, '【 電話番号 】'),
|
36
42
|
|
37
43
|
];
|
38
44
|
|
39
45
|
}
|
40
46
|
|
47
|
+
function fetchDataInSplit(str, header) {
|
41
48
|
|
49
|
+
const text = str.split(/(【.+?】)/);
|
42
50
|
|
43
|
-
|
51
|
+
const headerIndex = text.indexOf(header);
|
44
52
|
|
45
|
-
const res = str.match(new RegExp(pre + '(.*?)' + suf));
|
46
|
-
|
47
|
-
return r
|
53
|
+
return text[headerIndex+1].trim();
|
48
54
|
|
49
55
|
}
|
50
56
|
|