回答編集履歴
1
a
answer
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
[過去質問](https://teratail.com/questions/219231)参照のこと。
|
2
2
|
|
3
3
|
```javascript
|
4
|
-
function q219571(){
|
4
|
+
function q219571() {
|
5
5
|
const mailQuery = 'subject:お問い合わせ';
|
6
6
|
const threads = GmailApp.search(mailQuery);
|
7
|
-
const messages = GmailApp.getMessagesForThreads(threads).reduce(function (a,c) {
|
7
|
+
const messages = GmailApp.getMessagesForThreads(threads).reduce(function (a, c) {
|
8
|
+
return a.concat(c.map(mailToArray))
|
9
|
+
}, []);
|
8
10
|
const sheet = SpreadsheetApp.getActiveSheet();
|
9
11
|
const r = sheet.getLastRow();
|
10
|
-
sheet.getRange(r+1, 1
|
12
|
+
sheet.getRange(r + 1, 1, messages.length, 3).setValues(messages);
|
11
13
|
|
12
14
|
}
|
15
|
+
|
13
16
|
function messageToArray(m) {
|
14
17
|
const body = m.getPlainBody();
|
15
18
|
return [
|
16
|
-
|
19
|
+
fetchDataInSplit(body, '【 お名前 】'),
|
17
|
-
|
20
|
+
fetchDataInSplit(body, '【 メールアドレス 】'),
|
18
|
-
|
21
|
+
fetchDataInSplit(body, '【 電話番号 】'),
|
19
22
|
];
|
20
23
|
}
|
21
|
-
|
22
|
-
function
|
24
|
+
function fetchDataInSplit(str, header) {
|
23
|
-
const
|
25
|
+
const text = str.split(/(【.+?】)/);
|
26
|
+
const headerIndex = text.indexOf(header);
|
24
|
-
return
|
27
|
+
return text[headerIndex+1].trim();
|
25
28
|
}
|
26
29
|
```
|