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

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,7 @@
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
+ private replyEmail;
8
5
  private getHeader;
9
6
  private getBody;
10
7
  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,41 +66,38 @@ 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
+ replyEmail(id, threadId, body) {
75
72
  return __awaiter(this, void 0, void 0, function* () {
76
73
  yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
77
- if (ids.id) {
78
- const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
74
+ const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
75
+ userId: "me",
76
+ id: id,
77
+ format: 'FULL'
78
+ });
79
+ if (gmailResponse.data.payload) {
80
+ const message_subject = this.getHeader('subject', gmailResponse);
81
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
82
+ const reply_to = this.getHeader('reply-to', gmailResponse);
83
+ const options = {
84
+ to: reply_to,
85
+ from: this.getCurrentUserEmail(),
86
+ subject: `Re: ${message_subject}`,
87
+ references: message_messageID,
88
+ inReplyTo: [message_messageID],
89
+ html: body
90
+ };
91
+ const mailComposer = new MailComposer(options);
92
+ const message = yield mailComposer.compile().build();
93
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
94
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
79
95
  userId: "me",
80
- id: ids.id,
81
- format: 'FULL'
96
+ requestBody: {
97
+ threadId: threadId,
98
+ raw: encodeMessage
99
+ }
82
100
  });
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
- }
106
101
  }
107
102
  });
108
103
  }
@@ -1,10 +1,7 @@
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
+ private replyEmail;
8
5
  private getHeader;
9
6
  private getBody;
10
7
  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,41 +60,38 @@ 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
+ replyEmail(id, threadId, body) {
69
66
  return __awaiter(this, void 0, void 0, function* () {
70
67
  yield AuxGoogleAuth.setup();
71
- if (ids.id) {
72
- const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
68
+ const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
69
+ userId: "me",
70
+ id: id,
71
+ format: 'FULL'
72
+ });
73
+ if (gmailResponse.data.payload) {
74
+ const message_subject = this.getHeader('subject', gmailResponse);
75
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
76
+ const reply_to = this.getHeader('reply-to', gmailResponse);
77
+ const options = {
78
+ to: reply_to,
79
+ from: this.getCurrentUserEmail(),
80
+ subject: `Re: ${message_subject}`,
81
+ references: message_messageID,
82
+ inReplyTo: [message_messageID],
83
+ html: body
84
+ };
85
+ const mailComposer = new MailComposer(options);
86
+ const message = yield mailComposer.compile().build();
87
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
88
+ yield AuxGoogleAuth.gmailClient.users.messages.send({
73
89
  userId: "me",
74
- id: ids.id,
75
- format: 'FULL'
90
+ requestBody: {
91
+ threadId: threadId,
92
+ raw: encodeMessage
93
+ }
76
94
  });
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
- }
100
95
  }
101
96
  });
102
97
  }