@xuda.io/account_module 1.2.1323 → 1.2.1325
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +1 -112
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -990,117 +990,6 @@ export const search_users = async function (req) {
|
|
|
990
990
|
}
|
|
991
991
|
};
|
|
992
992
|
|
|
993
|
-
export const read_emails = async function (req, job_id, headers) {
|
|
994
|
-
const { uid, email_account_address, email_account_id, accessToken, vendor } = req;
|
|
995
|
-
|
|
996
|
-
const email_module = await import(`${module_path}/email_module/index.mjs`);
|
|
997
|
-
|
|
998
|
-
const read_mailbox = async function (mailbox_path, mailbox_name, is_sent) {
|
|
999
|
-
var emails_ret = await db_module.find_couch_query('xuda_emails', {
|
|
1000
|
-
selector: {
|
|
1001
|
-
docType: 'email',
|
|
1002
|
-
uid,
|
|
1003
|
-
email_account_address,
|
|
1004
|
-
email_account_id,
|
|
1005
|
-
mailbox_path,
|
|
1006
|
-
},
|
|
1007
|
-
fields: ['message.seq'],
|
|
1008
|
-
limit: 1,
|
|
1009
|
-
sort: [{ 'message.seq': 'desc' }],
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
var imap_ret;
|
|
1013
|
-
|
|
1014
|
-
const seq = emails_ret?.docs?.[0]?.message?.seq || 1;
|
|
1015
|
-
imap_ret = await email_module.query_imap({
|
|
1016
|
-
email_account_address,
|
|
1017
|
-
type: 'all',
|
|
1018
|
-
boxLock: mailbox_path,
|
|
1019
|
-
seq,
|
|
1020
|
-
accessToken,
|
|
1021
|
-
});
|
|
1022
|
-
|
|
1023
|
-
var senders = {};
|
|
1024
|
-
var recipient = {};
|
|
1025
|
-
var docs = [];
|
|
1026
|
-
|
|
1027
|
-
for await (let message of imap_ret) {
|
|
1028
|
-
delete message.modseq;
|
|
1029
|
-
if (message.seq > seq) {
|
|
1030
|
-
docs.push({
|
|
1031
|
-
_id: await _common.xuda_get_uuid('email'),
|
|
1032
|
-
docType: 'email',
|
|
1033
|
-
uid,
|
|
1034
|
-
email_account_address,
|
|
1035
|
-
email_account_id,
|
|
1036
|
-
message,
|
|
1037
|
-
mailbox_path,
|
|
1038
|
-
mailbox_name,
|
|
1039
|
-
});
|
|
1040
|
-
|
|
1041
|
-
let email_address = is_sent ? recipient[message.envelope.to[0].address] : senders[message.envelope.sender[0].address];
|
|
1042
|
-
let email_name = is_sent ? message.envelope.to[0].name : message.envelope.sender[0].name;
|
|
1043
|
-
const subject = message.envelope.subject;
|
|
1044
|
-
|
|
1045
|
-
recipient[email_address] = { name: email_name, is_sent, subject };
|
|
1046
|
-
|
|
1047
|
-
// if (is_sent) {
|
|
1048
|
-
// recipient[message.envelope.to[0].address] = message.envelope.to[0].name;
|
|
1049
|
-
// } else {
|
|
1050
|
-
// const is_spam = await ai_module.is_spam_email(uid, email_address, subject);
|
|
1051
|
-
// senders[message.envelope.sender[0].address] = message.envelope.sender[0].name;
|
|
1052
|
-
// }
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
if (docs.length) {
|
|
1057
|
-
await db_module.save_couch_bulk_docs('xuda_emails', docs);
|
|
1058
|
-
|
|
1059
|
-
for await (let [email, data] of Object.entries(is_sent ? recipient : senders)) {
|
|
1060
|
-
const { name, subject, is_sent } = data;
|
|
1061
|
-
|
|
1062
|
-
await add_contact({ uid, name, email, metadata: { subject, is_sent }, source: 'read emails' }, job_id, headers);
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
const mailboxes_ret = await email_module.list_mailboxes({
|
|
1068
|
-
email_account_address,
|
|
1069
|
-
email_account_id,
|
|
1070
|
-
accessToken,
|
|
1071
|
-
});
|
|
1072
|
-
|
|
1073
|
-
for await (let mailbox_obj of mailboxes_ret) {
|
|
1074
|
-
switch (vendor) {
|
|
1075
|
-
case 'gmail':
|
|
1076
|
-
if (!['[Gmail]/Starred', '[Gmail]/Drafts', '[Gmail]/All Mail', '[Gmail]/Spam', '[Gmail]/Trash', '[Gmail]', '[Gmail]/Important'].includes(mailbox_obj.path)) {
|
|
1077
|
-
await read_mailbox(mailbox_obj.path, mailbox_obj.name, mailbox_obj.path === '[Gmail]/Sent Mail');
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
break;
|
|
1081
|
-
|
|
1082
|
-
default:
|
|
1083
|
-
if (['INBOX', 'Sent Mail'].includes(mailbox_obj.path)) {
|
|
1084
|
-
await read_mailbox(mailbox_obj.path, mailbox_obj.name);
|
|
1085
|
-
}
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
|
|
1091
|
-
export const get_email_accounts = async function (req) {
|
|
1092
|
-
const { uid, stat } = req;
|
|
1093
|
-
const app_id = await get_account_default_project_id(uid);
|
|
1094
|
-
const db_module = await import(`${module_path}/db_module/index.mjs`);
|
|
1095
|
-
var email_account_ret = await db_module.find_app_couch_query(app_id, {
|
|
1096
|
-
selector: {
|
|
1097
|
-
docType: 'email_account',
|
|
1098
|
-
stat: stat || 3,
|
|
1099
|
-
},
|
|
1100
|
-
});
|
|
1101
|
-
return { code: 1, data: email_account_ret };
|
|
1102
|
-
};
|
|
1103
|
-
|
|
1104
993
|
const generate_gmail_access_token = async function (email_account) {
|
|
1105
994
|
return new Promise((resolve, reject) => {
|
|
1106
995
|
fetch('https://oauth2.googleapis.com/token', {
|
|
@@ -2848,7 +2737,7 @@ export const archive_account_profile = async function (req) {
|
|
|
2848
2737
|
};
|
|
2849
2738
|
|
|
2850
2739
|
export const delete_account_profile = async function (req, job_id, headers) {
|
|
2851
|
-
const { profile_id } = req;
|
|
2740
|
+
const { profile_id, uid } = req;
|
|
2852
2741
|
try {
|
|
2853
2742
|
const app_id = await get_account_default_project_id(uid);
|
|
2854
2743
|
var account_profile_doc = await db_module.get_app_couch_doc_native(app_id, profile_id);
|