@auxcode/auxta 1.3.23-beta.6 → 1.3.23-beta.8

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.
@@ -1,10 +1,9 @@
1
1
  import { gmail_v1 } from "googleapis";
2
2
  export declare class EmailHelper {
3
- verifyEmail(from_name: string, from_email: string, subject: string, body: string): Promise<{}>;
4
- replyEmail(ids: {
5
- id: string;
6
- threadId: string;
7
- }, body: string): Promise<void>;
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<void>;
4
+ sendEmail(to: string, subject: string, body: string): Promise<void>;
5
+ private replyEmail;
6
+ private static send;
8
7
  private getHeader;
9
8
  private getBody;
10
9
  private getCurrentUserEmail;
@@ -19,7 +19,7 @@ const buffer_1 = require("buffer");
19
19
  const AuxTA_1 = require("../../AuxTA");
20
20
  const MailComposer = require('nodemailer/lib/mail-composer');
21
21
  class EmailHelper {
22
- verifyEmail(from_name, from_email, subject, body) {
22
+ verifyEmail(from_name, from_email, subject, body, reply = false, reply_body) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
25
25
  const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
@@ -46,10 +46,6 @@ class EmailHelper {
46
46
  if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
47
47
  message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
48
48
  log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
49
- const returnData = {
50
- id: gmailResponse.data.id.toString(),
51
- threadId: gmailResponse.data.threadId.toString()
52
- };
53
49
  yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
54
50
  userId: "me",
55
51
  id: gmailResponse.data.id,
@@ -58,7 +54,9 @@ class EmailHelper {
58
54
  'removeLabelIds': ['UNREAD']
59
55
  }
60
56
  });
61
- return returnData;
57
+ if (reply && reply_body) {
58
+ yield this.replyEmail(gmailResponse.data.id.toString(), gmailResponse.data.threadId.toString(), reply_body);
59
+ }
62
60
  }
63
61
  }
64
62
  break;
@@ -68,44 +66,57 @@ class EmailHelper {
68
66
  timeoutCount += 12000;
69
67
  }
70
68
  yield log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.FAILED);
71
- return {};
72
69
  });
73
70
  }
74
- replyEmail(ids, body) {
71
+ sendEmail(to, subject, body) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const options = {
74
+ to: to,
75
+ from: this.getCurrentUserEmail(),
76
+ subject: subject,
77
+ html: body
78
+ };
79
+ yield EmailHelper.send(options);
80
+ });
81
+ }
82
+ replyEmail(id, threadId, body) {
75
83
  return __awaiter(this, void 0, void 0, function* () {
76
84
  yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
77
- if (ids.id) {
78
- const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
79
- userId: "me",
80
- id: ids.id,
81
- format: 'FULL'
82
- });
83
- if (gmailResponse.data.payload) {
84
- const message_subject = this.getHeader('subject', gmailResponse);
85
- const message_messageID = this.getHeader('Message-ID', gmailResponse);
86
- const reply_to = this.getHeader('reply-to', gmailResponse);
87
- const options = {
88
- to: reply_to,
89
- from: this.getCurrentUserEmail(),
90
- subject: `Re: ${message_subject}`,
91
- references: message_messageID,
92
- inReplyTo: [message_messageID],
93
- html: body
94
- };
95
- const mailComposer = new MailComposer(options);
96
- const message = yield mailComposer.compile().build();
97
- const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
98
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
99
- userId: "me",
100
- requestBody: {
101
- threadId: ids.threadId,
102
- raw: encodeMessage
103
- }
104
- });
105
- }
85
+ const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
86
+ userId: "me",
87
+ id: id,
88
+ format: 'FULL'
89
+ });
90
+ if (gmailResponse.data.payload) {
91
+ const message_subject = this.getHeader('subject', gmailResponse);
92
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
93
+ const reply_to = this.getHeader('reply-to', gmailResponse);
94
+ const options = {
95
+ to: reply_to,
96
+ from: this.getCurrentUserEmail(),
97
+ subject: `Re: ${message_subject}`,
98
+ references: message_messageID,
99
+ inReplyTo: [message_messageID],
100
+ html: body
101
+ };
102
+ yield EmailHelper.send(options, threadId);
106
103
  }
107
104
  });
108
105
  }
106
+ static send(options, threadId) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const mailComposer = new MailComposer(options);
109
+ const message = yield mailComposer.compile().build();
110
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
111
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
112
+ userId: "me",
113
+ requestBody: {
114
+ threadId: threadId,
115
+ raw: encodeMessage
116
+ }
117
+ });
118
+ });
119
+ }
109
120
  getHeader(value, headers) {
110
121
  for (const header of headers.data.payload.headers) {
111
122
  if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
@@ -1,10 +1,9 @@
1
1
  import { gmail_v1 } from "googleapis";
2
2
  export declare class EmailHelper {
3
- verifyEmail(from_name: string, from_email: string, subject: string, body: string): Promise<{}>;
4
- replyEmail(ids: {
5
- id: string;
6
- threadId: string;
7
- }, body: string): Promise<void>;
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<void>;
4
+ sendEmail(to: string, subject: string, body: string): Promise<void>;
5
+ private replyEmail;
6
+ private static send;
8
7
  private getHeader;
9
8
  private getBody;
10
9
  private getCurrentUserEmail;
@@ -13,7 +13,7 @@ import { atob } from "buffer";
13
13
  import { StepStatus } from "../../AuxTA";
14
14
  const MailComposer = require('nodemailer/lib/mail-composer');
15
15
  export class EmailHelper {
16
- verifyEmail(from_name, from_email, subject, body) {
16
+ verifyEmail(from_name, from_email, subject, body, reply = false, reply_body) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  yield AuxGoogleAuth.setup();
19
19
  const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
@@ -40,10 +40,6 @@ export class EmailHelper {
40
40
  if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
41
41
  message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
42
42
  log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
43
- const returnData = {
44
- id: gmailResponse.data.id.toString(),
45
- threadId: gmailResponse.data.threadId.toString()
46
- };
47
43
  yield AuxGoogleAuth.gmailClient.users.messages.modify({
48
44
  userId: "me",
49
45
  id: gmailResponse.data.id,
@@ -52,7 +48,9 @@ export class EmailHelper {
52
48
  'removeLabelIds': ['UNREAD']
53
49
  }
54
50
  });
55
- return returnData;
51
+ if (reply && reply_body) {
52
+ yield this.replyEmail(gmailResponse.data.id.toString(), gmailResponse.data.threadId.toString(), reply_body);
53
+ }
56
54
  }
57
55
  }
58
56
  break;
@@ -62,44 +60,57 @@ export class EmailHelper {
62
60
  timeoutCount += 12000;
63
61
  }
64
62
  yield log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
65
- return {};
66
63
  });
67
64
  }
68
- replyEmail(ids, body) {
65
+ sendEmail(to, subject, body) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const options = {
68
+ to: to,
69
+ from: this.getCurrentUserEmail(),
70
+ subject: subject,
71
+ html: body
72
+ };
73
+ yield EmailHelper.send(options);
74
+ });
75
+ }
76
+ replyEmail(id, threadId, body) {
69
77
  return __awaiter(this, void 0, void 0, function* () {
70
78
  yield AuxGoogleAuth.setup();
71
- if (ids.id) {
72
- const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
73
- userId: "me",
74
- id: ids.id,
75
- format: 'FULL'
76
- });
77
- if (gmailResponse.data.payload) {
78
- const message_subject = this.getHeader('subject', gmailResponse);
79
- const message_messageID = this.getHeader('Message-ID', gmailResponse);
80
- const reply_to = this.getHeader('reply-to', gmailResponse);
81
- const options = {
82
- to: reply_to,
83
- from: this.getCurrentUserEmail(),
84
- subject: `Re: ${message_subject}`,
85
- references: message_messageID,
86
- inReplyTo: [message_messageID],
87
- html: body
88
- };
89
- const mailComposer = new MailComposer(options);
90
- const message = yield mailComposer.compile().build();
91
- const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
92
- yield AuxGoogleAuth.gmailClient.users.messages.send({
93
- userId: "me",
94
- requestBody: {
95
- threadId: ids.threadId,
96
- raw: encodeMessage
97
- }
98
- });
99
- }
79
+ const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
80
+ userId: "me",
81
+ id: id,
82
+ format: 'FULL'
83
+ });
84
+ if (gmailResponse.data.payload) {
85
+ const message_subject = this.getHeader('subject', gmailResponse);
86
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
87
+ const reply_to = this.getHeader('reply-to', gmailResponse);
88
+ const options = {
89
+ to: reply_to,
90
+ from: this.getCurrentUserEmail(),
91
+ subject: `Re: ${message_subject}`,
92
+ references: message_messageID,
93
+ inReplyTo: [message_messageID],
94
+ html: body
95
+ };
96
+ yield EmailHelper.send(options, threadId);
100
97
  }
101
98
  });
102
99
  }
100
+ static send(options, threadId) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const mailComposer = new MailComposer(options);
103
+ const message = yield mailComposer.compile().build();
104
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
105
+ yield AuxGoogleAuth.gmailClient.users.messages.send({
106
+ userId: "me",
107
+ requestBody: {
108
+ threadId: threadId,
109
+ raw: encodeMessage
110
+ }
111
+ });
112
+ });
113
+ }
103
114
  getHeader(value, headers) {
104
115
  for (const header of headers.data.payload.headers) {
105
116
  if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {