diff --git a/.gitignore b/.gitignore index 9c63eb1..f2b5c32 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /qodana.yaml /todo.txt !/qodana.yaml +/attachments/ diff --git a/Writerside/images/image.png b/Writerside/images/image.png new file mode 100644 index 0000000..2d107b7 Binary files /dev/null and b/Writerside/images/image.png differ diff --git a/Writerside/images/image_1.png b/Writerside/images/image_1.png new file mode 100644 index 0000000..2957d9d Binary files /dev/null and b/Writerside/images/image_1.png differ diff --git a/Writerside/topics/readMessage.md b/Writerside/topics/readMessage.md index 0fda13f..4738e92 100644 --- a/Writerside/topics/readMessage.md +++ b/Writerside/topics/readMessage.md @@ -16,6 +16,7 @@ The `readMessage()` function in Easy-Yopmail allows you to read the content of a - **`selector`**: (Optional) A CSS selector to target a specific element within the HTML email body. - **`attribute`**: (Optional) If a selector is provided, this parameter specifies the attribute of the element to be returned (e.g., "href" for a link). - **`pathToSave`**: (Optional) Path to save the email HTML as a file. +- **`saveAttachments`**: (Optional) Boolean flag to save email attachments to the project download folder. ## Output @@ -26,6 +27,8 @@ The `readMessage()` function returns a promise that resolves with an object cont - **`from`**: The sender's email address. - **`date`**: The date the email was received. - **`deliverability`**: Information about the email delivery. +- **`attachments`**: An array of attachment objects (if `saveAttachments` is enabled). +- **`saveAttachments`**: A boolean flag indicating if attachments were saved. - **`format`**: The format of the returned content ("TXT" or "HTML"). - **`selector`**: The CSS selector used (if provided). - **`eq`**: The index of the selected element (if provided). @@ -34,6 +37,7 @@ The `readMessage()` function returns a promise that resolves with an object cont - **`content`**: The content of the email in the specified format. - **`info`**: A list of warnings or informational messages. + ## Mermaid Diagram ```mermaid @@ -84,6 +88,37 @@ easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', pathToSave: '. }); ``` +### 4. Read Email Content and Save Attachments + +```javascript +easyYopmail.readMessage('my-email', 'email-id', { saveAttachment: true }) +.then(message => { + if (message.saveAttachments) { + console.log('Attachments saved to download folder'); + } +}); + +// Output: +// Attachments saved to download folder +attachments: [ + { + fullName: 'prueba1.rar', + name: 'prueba1', + extension: 'rar', + file: 'https://yopmail.com//cid?b=jasp402&id=e_ZwDkZGN4ZGVmZQR5ZQNjAGD4AwL5BD==&cd=a&pj=f_m38pqbyv1' + }, + { + fullName: 'prueba2.zip', + name: 'prueba2', + extension: 'zip', + file: 'https://yopmail.com//cid?b=jasp402&id=e_ZwDkZGN4ZGVmZQR5ZQNjAGD4AwL5BD==&cd=a&pj=f_m38pqbyg0' + } +] +``` +![image.png](image.png) +>**Note:** In order for attachments to be downloaded, the email must contain such files. Please check if your email contains attachments before downloading. This feature also negatively impacts performance, as responses are blocked until the download is complete. +>{style="warning"} + ## Code Example ```javascript diff --git a/index.js b/index.js index 6d1c9bd..f0b1b7c 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -"use strict";const querystring=require("querystring"),Core=require("./src/core.js");class EasyYopmail extends Core{async getMail(){try{const{location:a}=await this.getHttpSettings();let b=this.constants.URL_GENERATOR(a);const c=await this.request("GET",b);200!==c.statusCode&&this.handleError({customMessage:this.constants.ERROR_LOAD_PAGE});const d=this.loadHTMl(c.body),e=d(this.constants.S_INPUT_MAIL_GENERATE).text();return e.split(";")[1]||e}catch(a){this.handleError({customMessage:a,error:this.constants.ERROR_LOAD_PAGE})}}async getInbox(a){let b=1{const b=a.lastIndexOf(".");if(-1===b)return{name:a,extension:""};else{const c=a.substring(0,b),d=a.substring(b+1);return{name:c,extension:d}}},F=[];return C.length&&C.find("a").length&&C.find("a").each(((a,b)=>{const c=u(b),d=c.attr("title"),e=c.attr("href"),f=this.constants.URL_BASE+e,{name:g,extension:h}=E(d);F.push({fullName:d,name:g,extension:h,file:f}),q&&this.downloadAttachments(f,d,s)})),B.length&&(D.content=B.text().replace(/\n/,"").trim()),o&&this.saveEmailHTML(o,t.body.replace('href="/ver/9.2/style.css"',`href="https://yopmail.com/ver/${g}/style.css"`),b),{id:b,submit:v,from:y,date:z,deliverability:A,attachments:F,saveAttachment:q,format:l,selector:m,eq:p?`eq(${p})`:null,attribute:n,pathToSave:o,content:D.content,info:D.info}}catch(a){this.handleError({customMessage:this.constants.ERROR_READ_MESSAGE,error:a})}}async deleteMessage(a,b){try{let{location:c,version:d,cookie:e,yp:f,yj:g,T:h,RT:i,ytime:j}=await this.getHttpSettings();const k=this.constants.HEADERS_INBOX(e,a,c,h,i,j),l=this.constants.URL_DELETE_MESSAGE(a,b,f,g,d,c),m=this.constants.URL_READ_MAIL(a,b,c),n=await this.request("GET",m,k);if(200!==n.statusCode)return this.constants.NOTIFY_EMAIL_NOT_FOUND(b);else{const a=await this.request("GET",l,k);return 200===a.statusCode?this.constants.NOTIFY_EMAIL_DELETED_SUCCESS(b):this.constants.NOTIFY_EMAIL_DELETED_FAILED(b)}}catch(a){this.handleError({customMessage:this.constants.ERROR_DELETE_MESSAGE,error:a})}}async deleteInbox(a){try{const{totalEmails:b,inbox:c}=await this.getInbox(a);if(0''['concat'](baseUrl,a0_0x91f9aa(0x17b))[a0_0x91f9aa(0x15c)](_0x4df92c,a0_0x91f9aa(0x16e)),'URL_SEND_MESSAGE':_0x11bb7a=>''[a0_0x91f9aa(0x15c)](baseUrl)[a0_0x91f9aa(0x15c)](_0x11bb7a,a0_0x91f9aa(0x156)),'URL_GENERATOR':_0x17d377=>''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0x17d377,a0_0x91f9aa(0x176)),'URL_WRITE_MAIL':(_0x346d1b,_0x464386)=>''['concat'](baseUrl)['concat'](_0x464386,a0_0x91f9aa(0x163))[a0_0x91f9aa(0x15c)](_0x346d1b,a0_0x91f9aa(0x13c)),'URL_READ_MAIL':(_0x365469,_0x18fffd,_0x2fefbc)=>''[a0_0x91f9aa(0x15c)](baseUrl)[a0_0x91f9aa(0x15c)](_0x2fefbc,a0_0x91f9aa(0x191))[a0_0x91f9aa(0x15c)](_0x365469,a0_0x91f9aa(0x18d))['concat'](_0x18fffd),'URL_DELETE_INBOX':(_0x3a434d,_0x5630ae,_0x1e71b9,_0x5cd4a6,_0x31e988,_0xb7439)=>''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0xb7439,a0_0x91f9aa(0x18e))[a0_0x91f9aa(0x15c)](_0x3a434d,a0_0x91f9aa(0x18c))[a0_0x91f9aa(0x15c)](_0x5630ae,a0_0x91f9aa(0x14f))[a0_0x91f9aa(0x15c)](_0x1e71b9,a0_0x91f9aa(0x16f))[a0_0x91f9aa(0x15c)](_0x5cd4a6,'&v=')[a0_0x91f9aa(0x15c)](_0x31e988,'&r_c=&id=&ad=0'),'URL_DELETE_MESSAGE':(_0x3a5dd8,_0x533fcc,_0x1255da,_0x49e891,_0x30bd39,_0x1c0d2f)=>''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0x1c0d2f,'/inbox?login=')[a0_0x91f9aa(0x15c)](_0x3a5dd8,a0_0x91f9aa(0x155))[a0_0x91f9aa(0x15c)](_0x533fcc,'&ctrl=&yp=')[a0_0x91f9aa(0x15c)](_0x1255da,a0_0x91f9aa(0x16f))[a0_0x91f9aa(0x15c)](_0x49e891,'&v=')['concat'](_0x30bd39,'&r_c=&id=&ad=0'),'URL_INBOX':(_0x75387a,_0x803cd8,_0x1ca3ad,_0x5842d7,_0xe4651e,_0xdd7a80)=>''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0xdd7a80,a0_0x91f9aa(0x18e))[a0_0x91f9aa(0x15c)](_0x75387a,'&p=')[a0_0x91f9aa(0x15c)](_0xe4651e,a0_0x91f9aa(0x133))[a0_0x91f9aa(0x15c)](_0x803cd8,a0_0x91f9aa(0x16f))[a0_0x91f9aa(0x15c)](_0x1ca3ad,a0_0x91f9aa(0x136))['concat'](_0x5842d7,a0_0x91f9aa(0x192))},HTTP_CONFIG={'HEADERS_INBOX':(_0x1db8d8,_0x3ef64d,_0x5cb1c7,_0x3e27d5,_0x508657,_0x29040e)=>({'headers':{...baseHeaders,'accept':a0_0x91f9aa(0x15a),'cookie':''[a0_0x91f9aa(0x15c)](_0x1db8d8,';\x20compte=')[a0_0x91f9aa(0x15c)](_0x3ef64d,a0_0x91f9aa(0x17e))['concat'](_0x3ef64d,a0_0x91f9aa(0x150))[a0_0x91f9aa(0x15c)](gads,':T=')[a0_0x91f9aa(0x15c)](_0x3e27d5,':RT=')['concat'](_0x508657,a0_0x91f9aa(0x15d))[a0_0x91f9aa(0x15c)](gads_S,';\x20__gpi=')[a0_0x91f9aa(0x15c)](gpi,':T=')[a0_0x91f9aa(0x15c)](_0x3e27d5,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x508657,a0_0x91f9aa(0x15d))[a0_0x91f9aa(0x15c)](gpi_S,a0_0x91f9aa(0x182))['concat'](eoi,a0_0x91f9aa(0x149))['concat'](_0x3e27d5,a0_0x91f9aa(0x17d))['concat'](_0x508657,a0_0x91f9aa(0x15d))['concat'](eoi_S,'\x22;\x20FCNEC=')[a0_0x91f9aa(0x15c)](FCNEC,a0_0x91f9aa(0x183))[a0_0x91f9aa(0x15c)](_0x3ef64d,a0_0x91f9aa(0x17e))[a0_0x91f9aa(0x15c)](_0x3ef64d,';\x20ytime=')[a0_0x91f9aa(0x15c)](_0x29040e),'referer':''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0x5cb1c7,a0_0x91f9aa(0x134)),'sec-fetch-dest':a0_0x91f9aa(0x177),'sec-fetch-mode':'navigate','sec-fetch-user':'?1','upgrade-insecure-requests':'1'}}),'HEADERS_READ_MESSAGE':(_0x5e599a,_0xddee46,_0x1eb858,_0x3d6521,_0x1af073,_0x52d983)=>({'headers':{...baseHeaders,'accept':a0_0x91f9aa(0x13d),'Accept-Encoding':'gzip,\x20deflate,\x20br,\x20zstd','cookie':''[a0_0x91f9aa(0x15c)](_0x5e599a,a0_0x91f9aa(0x150))[a0_0x91f9aa(0x15c)](gads,a0_0x91f9aa(0x149))['concat'](_0x3d6521,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x1af073,a0_0x91f9aa(0x15d))['concat'](gads_S,';\x20__gpi=')['concat'](gpi,':T=')[a0_0x91f9aa(0x15c)](_0x3d6521,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x1af073,a0_0x91f9aa(0x15d))[a0_0x91f9aa(0x15c)](gpi_S,a0_0x91f9aa(0x182))[a0_0x91f9aa(0x15c)](eoi,a0_0x91f9aa(0x149))[a0_0x91f9aa(0x15c)](_0x3d6521,':RT=')['concat'](_0x1af073,':S=')[a0_0x91f9aa(0x15c)](eoi_S,a0_0x91f9aa(0x148))[a0_0x91f9aa(0x15c)](FCNEC,a0_0x91f9aa(0x165))[a0_0x91f9aa(0x15c)](_0xddee46,';\x20ywm=')[a0_0x91f9aa(0x15c)](_0xddee46,';\x20ytime=')[a0_0x91f9aa(0x15c)](_0x52d983),'referer':''[a0_0x91f9aa(0x15c)](baseUrl)['concat'](_0x1eb858,a0_0x91f9aa(0x134)),'sec-fetch-dest':a0_0x91f9aa(0x177),'sec-fetch-mode':a0_0x91f9aa(0x152),'sec-fetch-user':'?1','upgrade-insecure-requests':'1'}}),'HEADERS_WRITE_MESSAGE':(_0x31f4ee,_0x163ac6,_0x365a91,_0x55860e,_0x5c020c,_0x126d4e)=>({'headers':{...baseHeaders,'accept':a0_0x91f9aa(0x153),'Accept-Encoding':a0_0x91f9aa(0x18a),'content-type':a0_0x91f9aa(0x135),'cookie':''['concat'](_0x31f4ee,';\x20compte=')[a0_0x91f9aa(0x15c)](_0x163ac6,';\x20ywm=')['concat'](_0x163ac6,a0_0x91f9aa(0x150))[a0_0x91f9aa(0x15c)](gads,a0_0x91f9aa(0x149))[a0_0x91f9aa(0x15c)](_0x55860e,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x5c020c,a0_0x91f9aa(0x15d))['concat'](gads_S,a0_0x91f9aa(0x189))['concat'](gpi,':T=')[a0_0x91f9aa(0x15c)](_0x55860e,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x5c020c,':S=')['concat'](gpi_S,a0_0x91f9aa(0x182))[a0_0x91f9aa(0x15c)](eoi,a0_0x91f9aa(0x149))['concat'](_0x55860e,a0_0x91f9aa(0x17d))[a0_0x91f9aa(0x15c)](_0x5c020c,a0_0x91f9aa(0x15d))['concat'](eoi_S,a0_0x91f9aa(0x148))[a0_0x91f9aa(0x15c)](FCNEC,a0_0x91f9aa(0x183))[a0_0x91f9aa(0x15c)](_0x163ac6,a0_0x91f9aa(0x17e))['concat'](_0x163ac6,a0_0x91f9aa(0x15e))[a0_0x91f9aa(0x15c)](_0x126d4e),'origin':a0_0x91f9aa(0x162),'referer':a0_0x91f9aa(0x138)[a0_0x91f9aa(0x15c)](_0x365a91,a0_0x91f9aa(0x134)),'sec-fetch-dest':'empty','sec-fetch-mode':'cors'}})},PATHS={'PATH_INBOX_FILE':a0_0x91f9aa(0x180),'PATH_MAIL_CONTENT':a0_0x91f9aa(0x18f),'PATH_HTML_ID':a0_0x91f9aa(0x16b),'PATH_HTML_SUBJECT':a0_0x91f9aa(0x187),'PATH_HTML_CONTENT':a0_0x91f9aa(0x172)},SELECTORS={'S_INPUT_YP':a0_0x91f9aa(0x166),'S_INPUT_MAIL_GENERATE':a0_0x91f9aa(0x158),'S_SUBMIT':a0_0x91f9aa(0x13f),'S_FROM':a0_0x91f9aa(0x188),'S_DATE':a0_0x91f9aa(0x140),'S_FROM_ALT':a0_0x91f9aa(0x160),'S_DATE_ALT':a0_0x91f9aa(0x14e),'S_MAIL':a0_0x91f9aa(0x157)},REGEXES={'REGEX_LOCATION':/lang="(.*?)"/,'REGEX_YJ':/&yj=([^&]+)&v=/,'REGEX_TOTAL_MAILS':/w\.finrmail\((.*?)\)/,'REGEX_VER':/\/ver\/(\d+\.\d+)\//},ERRORS={'ERROR_MAIL_INVALID':a0_0x91f9aa(0x13e),'ERROR_SEARCH_INVALID':a0_0x91f9aa(0x164),'ERROR_LOAD_PAGE':a0_0x91f9aa(0x141),'ERROR_GET_INBOX':a0_0x91f9aa(0x194),'ERROR_DELETE_INBOX':a0_0x91f9aa(0x18b),'ERROR_READ_MESSAGE':'readMessage():\x20Error\x20read\x20message','ERROR_READ_MESSAGE_FORMAT':'readMessage():\x20The\x20format\x20is\x20invalid.\x20Try\x20again\x20with\x20(HTML\x20or\x20TXT)','ERROR_READ_MESSAGE_ATTRIBUTE':a0_0x91f9aa(0x14b),'ERROR_READ_MESSAGE_STATUS_410':'readMessage():\x20The\x20message\x20has\x20been\x20deleted\x20or\x20does\x20not\x20exist.\x20Try\x20reviewing\x20the\x20ID','ERROR_WRITE_MESSAGE':'writeMessage():\x20Error\x20write\x20message','ERROR_DELETE_MESSAGE':a0_0x91f9aa(0x173),'ERROR_PARAMETERS_INVALID':a0_0x91f9aa(0x144),'ERROR_GET_COOKIES':a0_0x91f9aa(0x146),'ERROR_GET_VERSION':a0_0x91f9aa(0x170),'ERROR_MISSING_PARAMETERS':a0_0x91f9aa(0x14d),'ERROR_GET_TOTAL_MAILS':a0_0x91f9aa(0x161),'ERROR_GET_YJ':'Error\x20getting\x20YJ','ERROR_URL_NOT_FOUND':'URL\x20not\x20found,\x20Please\x20check\x20the\x20URL\x20try\x20again','ERROR_SAVE_HTML':a0_0x91f9aa(0x181)},NOTIFY={'NOTIFY_EMAIL_NOT_FOUND':_0x16a5a6=>a0_0x91f9aa(0x169)[a0_0x91f9aa(0x15c)](_0x16a5a6,a0_0x91f9aa(0x14a)),'NOTIFY_EMAIL_DELETED_SUCCESS':_0x1633f2=>'The\x20mail\x20with\x20ID\x20['[a0_0x91f9aa(0x15c)](_0x1633f2,a0_0x91f9aa(0x143)),'NOTIFY_EMAIL_DELETED_FAILED':_0x17d826=>a0_0x91f9aa(0x13a)[a0_0x91f9aa(0x15c)](_0x17d826,a0_0x91f9aa(0x151)),'NOTIFY_INBOX_DELETED_SUCCESS':(_0x2c548e,_0x5bcb44)=>'The\x20inbox\x20of\x20the\x20email\x20['[a0_0x91f9aa(0x15c)](_0x2c548e,a0_0x91f9aa(0x16a))[a0_0x91f9aa(0x15c)](_0x5bcb44,a0_0x91f9aa(0x13b)),'NOTIFY_INBOX_DELETED_FAILED':_0x1b3220=>'An\x20error\x20occurred\x20when\x20trying\x20to\x20delete\x20the\x20inbox\x20of\x20the\x20email\x20'[a0_0x91f9aa(0x15c)](_0x1b3220,a0_0x91f9aa(0x16c)),'NOTIFY_INBOX_EMPTY':a0_0x91f9aa(0x145)},TEST={'TEST_MAIL':a0_0x91f9aa(0x14c),'TEST_MAIL_RECEIVER':'receiver01@yopmail.com'};module[a0_0x91f9aa(0x154)]=Object['freeze']({...URLS,...HTTP_CONFIG,...PATHS,...SELECTORS,...REGEXES,...ERRORS,...NOTIFY,...TEST});function a0_0xf384(){const _0x136db5=['&yp=',';\x20__gads=','].\x20Try\x20again\x20later.','navigate','*/*','exports','&p=1&d=','/writepost','#mail','#geny','keep-alive','text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7','10nIEUpb','concat',':S=',';\x20ytime=','4507330nKRXpd','div.fl\x20>\x20div.md.text.zoom.nw.f18\x20>\x20span.ellipsis.b','Error\x20getting\x20total\x20number\x20of\x20mails','https://yopmail.com','/write?b=','parameters\x20\x27_search\x27\x20keys\x20is\x20invalid,\x20try\x20again\x20with\x20(subject\x20ot\x20content)',';\x20compte=','input#yp','8JiXPbC','ALNI_MZ3k3gFQXDYCyC-n7CnlRltSEFoVQ','The\x20mail\x20with\x20ID\x20[',']\x20has\x20been\x20deleted.\x20','tests/archives/mailHTML_id.html','.\x20Try\x20again\x20later.','5612002qMDSIl','/webmail.js','&yj=','Error\x20getting\x20version.\x20Error\x20loading\x20page','16QjgnYS','tests/archives/mailHTML_content.html','deleteMessage():\x20Error\x20delete\x20message','UID=00000a0a4f90dd17','3340266JvQviu','/email-generator','iframe','115583oFFhzJ','yopmail.com','ID=5cd00b43a530b6a4','ver/','Mozilla/5.0\x20(Windows\x20NT\x2010.0;\x20Win64;\x20x64)\x20AppleWebKit/537.36\x20(KHTML,\x20like\x20Gecko)\x20Chrome/113.0.0.0\x20Safari/537.36',':RT=',';\x20ywm=','ALNI_MbohrBpXt1O26O3LDmi-KRsCVPhcw','tests/archives/inbox.json','Error\x20saving\x20HTML\x20file',';\x20__eoi=\x22',';compte=','58074DUcYVF','12hTXtVZ','same-origin','tests/archives/mailHTML_subject.html','div.fl\x20>\x20div.md.text.zoom.nw.f24\x20>\x20span.ellipsis.b',';\x20__gpi=','gzip,\x20deflate,\x20br,\x20zstd','deleteInbox():\x20Error\x20delete\x20Inbox\x20page','&p=1&d=all&ctrl=','&id=i','/inbox?login=','tests/archives/mailContent.json','7XIRfSy','/mail?b=','&r_c=&id=&ad=0','%5B%5B%22AKsRol_M2LZFqBb7LSYXadLKqvJ5hTBhxAex9zsoE4N4YD_W5EKTjaIdnSjUL1onQWaOaUq-2HI8vZCE9bqnfMfFE9XOzzqfKK3c3UA5WvJQYW6YtylSfhXH3FZ4WTR9pzl8dTHsGaiJSwztPBvgXHwUPGcOlsELSQ%3D%3D%22%5D%5D','getInbox():\x20Error\x20getting\x20Inbox\x20page','&d=&ctrl=&yp=','/wm','application/x-www-form-urlencoded','&v=','518235DQEdJD','https://yopmail.com/','es-ES,es;q=0.9','occurred\x20a\x20error\x20when\x20trying\x20to\x20delete\x20the\x20mail\x20with\x20ID\x20[','\x20emails\x20have\x20been\x20deleted.','&id=','text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8','parameters\x20\x27mail\x27\x20is\x20required','div.fl\x20>\x20div.ellipsis.nw.b.f18','div.fl\x20>\x20div.md.text.zoom.nw.f24\x20>\x20span.ellipsis:last-child','getMail():\x20Error\x20getting\x20YOPMail\x20page','1400634tSPWHn',']\x20has\x20been\x20successfully\x20deleted.','validateSearch():\x20-\x20The\x20parameters\x20are\x20incorrect.\x20Try\x20again\x20with\x20(id,\x20from,\x20subject\x20or\x20timestamp)','The\x20inbox\x20is\x20empty','Error\x20getting\x20cookies','Windows','\x22;\x20FCNEC=',':T=',']\x20was\x20not\x20found\x20and\x20could\x20not\x20be\x20deleted.','readMessage():\x20Attribute\x20cannot\x20be\x20accessed\x20if\x20no\x20selector\x20is\x20defined','test@yopmail.com','Missing\x20parameters','div.fl\x20>\x20div.md.text.zoom.nw.f18\x20>\x20span.ellipsis:last-child'];a0_0xf384=function(){return _0x136db5;};return a0_0xf384();} \ No newline at end of file +'use strict';const a0_0x4e3b09=a0_0x33fb;(function(_0x5d4023,_0x1512e5){const _0x1bbbec=a0_0x33fb,_0x1a81c2=_0x5d4023();while(!![]){try{const _0x13c3cd=parseInt(_0x1bbbec(0x207))/0x1+-parseInt(_0x1bbbec(0x209))/0x2+parseInt(_0x1bbbec(0x213))/0x3+-parseInt(_0x1bbbec(0x21e))/0x4*(parseInt(_0x1bbbec(0x20a))/0x5)+-parseInt(_0x1bbbec(0x1f4))/0x6*(parseInt(_0x1bbbec(0x1f3))/0x7)+parseInt(_0x1bbbec(0x223))/0x8+parseInt(_0x1bbbec(0x22a))/0x9;if(_0x13c3cd===_0x1512e5)break;else _0x1a81c2['push'](_0x1a81c2['shift']());}catch(_0x4ffbc5){_0x1a81c2['push'](_0x1a81c2['shift']());}}}(a0_0x3053,0xc6472));let baseUrl=a0_0x4e3b09(0x233),baseHeaders={'accept-encoding':a0_0x4e3b09(0x222),'accept-language':a0_0x4e3b09(0x225),'connection':a0_0x4e3b09(0x227),'host':'yopmail.com','sec-ch-ua':'\x22Not_A\x20Brand\x22;v=\x2299\x22,\x20\x22Chromium\x22;v=\x22121\x22,\x20\x22Google\x20Chrome\x22;v=\x22121\x22','sec-ch-ua-mobile':'?0','sec-ch-ua-platform':a0_0x4e3b09(0x220),'sec-fetch-site':a0_0x4e3b09(0x1fc),'user-agent':'Mozilla/5.0\x20(Windows\x20NT\x2010.0;\x20Win64;\x20x64)\x20AppleWebKit/537.36\x20(KHTML,\x20like\x20Gecko)\x20Chrome/113.0.0.0\x20Safari/537.36'},gads=a0_0x4e3b09(0x240),gads_S='ALNI_MZ3k3gFQXDYCyC-n7CnlRltSEFoVQ',gpi=a0_0x4e3b09(0x200),gpi_S='ALNI_MbohrBpXt1O26O3LDmi-KRsCVPhcw',eoi=a0_0x4e3b09(0x1fa),eoi_S='AA-Afjb4QKVvFIwSmOYMSnui2gGd',FCNEC=a0_0x4e3b09(0x217);function a0_0x3053(){const _0x437a34=['&r_c=&id=&ad=0',']\x20has\x20been\x20deleted.\x20','An\x20error\x20occurred\x20when\x20trying\x20to\x20delete\x20the\x20inbox\x20of\x20the\x20email\x20','&yp=','getInbox():\x20Error\x20getting\x20Inbox\x20page','https://yopmail.com/','text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7','deleteInbox():\x20Error\x20delete\x20Inbox\x20page','\x20emails\x20have\x20been\x20deleted.',';\x20ytime=','Error\x20getting\x20version.\x20Error\x20loading\x20page','#mail','&v=','input#yp',':S=','Error\x20getting\x20cookies',';\x20__gpi=','#geny','ID=9a0b3cce9ff31bac',';\x20compte=','empty',';\x20ywm=','The\x20inbox\x20of\x20the\x20email\x20[','&ctrl=&yp=',';\x20__gads=','https://yopmail.com','tests/archives/mailHTML_subject.html','/mail?b=','exports','7GdNaxv','6214818cHXHKS','&d=&ctrl=&yp=','div.fl\x20>\x20div.md.text.zoom.nw.f24\x20>\x20span.ellipsis:last-child','receiver01@yopmail.com',':RT=','ver/','ID=5cd00b43a530b6a4','The\x20inbox\x20is\x20empty','same-origin','validateSearch():\x20-\x20The\x20parameters\x20are\x20incorrect.\x20Try\x20again\x20with\x20(id,\x20from,\x20subject\x20or\x20timestamp)','/wm','/inbox?login=','UID=00000a0a4f90dd17','Missing\x20parameters',';\x20__eoi=\x22','tests/archives/mailContent.json','&p=1&d=all&ctrl=','Error\x20getting\x20YJ','&id=i','794462afRapg','gzip,\x20deflate,\x20br,\x20zstd','2474662QNnczR','105435SOHRsD','occurred\x20a\x20error\x20when\x20trying\x20to\x20delete\x20the\x20mail\x20with\x20ID\x20[','.\x20Try\x20again\x20later.','/email-generator','getMail():\x20Error\x20getting\x20YOPMail\x20page','writeMessage():\x20Error\x20write\x20message','\x22;\x20FCNEC=','iframe',':T=','248961FyNJYv','URL\x20not\x20found,\x20Please\x20check\x20the\x20URL\x20try\x20again','readMessage():\x20Attribute\x20cannot\x20be\x20accessed\x20if\x20no\x20selector\x20is\x20defined','cors','%5B%5B%22AKsRol_M2LZFqBb7LSYXadLKqvJ5hTBhxAex9zsoE4N4YD_W5EKTjaIdnSjUL1onQWaOaUq-2HI8vZCE9bqnfMfFE9XOzzqfKK3c3UA5WvJQYW6YtylSfhXH3FZ4WTR9pzl8dTHsGaiJSwztPBvgXHwUPGcOlsELSQ%3D%3D%22%5D%5D','The\x20mail\x20with\x20ID\x20[','/webmail.js','tests/archives/inbox.json','freeze','div.fl\x20>\x20div.ellipsis.nw.b.f18','navigate','144KbsZaA','/write?b=','Windows','parameters\x20\x27_search\x27\x20keys\x20is\x20invalid,\x20try\x20again\x20with\x20(subject\x20ot\x20content)','gzip,\x20deflate,\x20br','4772664Miwndb','&p=1&d=','es-ES,es;q=0.9','parameters\x20\x27mail\x27\x20is\x20required','keep-alive','application/x-www-form-urlencoded','div.fl\x20>\x20div.md.text.zoom.nw.f18\x20>\x20span.ellipsis.b','21333420YhBtok','&yj=',';compte=','tests/archives/mailHTML_id.html'];a0_0x3053=function(){return _0x437a34;};return a0_0x3053();}const URLS={'URL_BASE':'https://yopmail.com/','URL_WEBMAIL_JS':_0x5b8421=>baseUrl+a0_0x4e3b09(0x1f9)+_0x5b8421+a0_0x4e3b09(0x219),'URL_SEND_MESSAGE':_0x514545=>''+baseUrl+_0x514545+'/writepost','URL_GENERATOR':_0x34e292=>''+baseUrl+_0x34e292+a0_0x4e3b09(0x20d),'URL_WRITE_MAIL':(_0x4b09ae,_0x16ba92)=>''+baseUrl+_0x16ba92+a0_0x4e3b09(0x21f)+_0x4b09ae+'&id=','URL_READ_MAIL':(_0x5dbeaa,_0x3da9bd,_0x1847eb)=>''+baseUrl+_0x1847eb+a0_0x4e3b09(0x249)+_0x5dbeaa+a0_0x4e3b09(0x206)+_0x3da9bd,'URL_DELETE_INBOX':(_0x9015eb,_0x109e6f,_0x4b7999,_0x5d0dd4,_0x2c5760,_0x738876)=>''+baseUrl+_0x738876+'/inbox?login='+_0x9015eb+a0_0x4e3b09(0x204)+_0x109e6f+a0_0x4e3b09(0x231)+_0x4b7999+'&yj='+_0x5d0dd4+a0_0x4e3b09(0x23a)+_0x2c5760+a0_0x4e3b09(0x22e),'URL_DELETE_MESSAGE':(_0x1ef9e3,_0x22c93e,_0x2fc741,_0x5e55cc,_0x4a0fde,_0x17c7ed)=>''+baseUrl+_0x17c7ed+a0_0x4e3b09(0x1ff)+_0x1ef9e3+a0_0x4e3b09(0x224)+_0x22c93e+a0_0x4e3b09(0x245)+_0x2fc741+a0_0x4e3b09(0x22b)+_0x5e55cc+'&v='+_0x4a0fde+'&r_c=&id=&ad=0','URL_INBOX':(_0x573c86,_0x8cc9f6,_0x536450,_0x51f016,_0xc3c07b,_0x29658c)=>''+baseUrl+_0x29658c+'/inbox?login='+_0x573c86+'&p='+_0xc3c07b+a0_0x4e3b09(0x1f5)+_0x8cc9f6+a0_0x4e3b09(0x22b)+_0x536450+a0_0x4e3b09(0x23a)+_0x51f016+a0_0x4e3b09(0x22e)},HTTP_CONFIG={'HEADERS_INBOX':(_0x3586b1,_0x2ce5bc,_0x4f45b2,_0x3fe165,_0x42b36a,_0x24e836)=>({'headers':{...baseHeaders,'accept':a0_0x4e3b09(0x234),'cookie':_0x3586b1+a0_0x4e3b09(0x241)+_0x2ce5bc+';\x20ywm='+_0x2ce5bc+';\x20__gads='+gads+':T='+_0x3fe165+':RT='+_0x42b36a+a0_0x4e3b09(0x23c)+gads_S+a0_0x4e3b09(0x23e)+gpi+a0_0x4e3b09(0x212)+_0x3fe165+a0_0x4e3b09(0x1f8)+_0x42b36a+a0_0x4e3b09(0x23c)+gpi_S+a0_0x4e3b09(0x202)+eoi+':T='+_0x3fe165+a0_0x4e3b09(0x1f8)+_0x42b36a+':S='+eoi_S+'\x22;\x20FCNEC='+FCNEC+a0_0x4e3b09(0x22c)+_0x2ce5bc+';\x20ywm='+_0x2ce5bc+a0_0x4e3b09(0x237)+_0x24e836,'referer':''+baseUrl+_0x4f45b2+'/wm','sec-fetch-dest':'iframe','sec-fetch-mode':a0_0x4e3b09(0x21d),'sec-fetch-user':'?1','upgrade-insecure-requests':'1'}}),'HEADERS_READ_MESSAGE':(_0x12127f,_0x5a8840,_0x5efce1,_0x3c4421,_0x5d1e67,_0x16eac3)=>({'headers':{...baseHeaders,'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8','Accept-Encoding':a0_0x4e3b09(0x208),'cookie':_0x12127f+a0_0x4e3b09(0x246)+gads+':T='+_0x3c4421+a0_0x4e3b09(0x1f8)+_0x5d1e67+a0_0x4e3b09(0x23c)+gads_S+a0_0x4e3b09(0x23e)+gpi+a0_0x4e3b09(0x212)+_0x3c4421+a0_0x4e3b09(0x1f8)+_0x5d1e67+a0_0x4e3b09(0x23c)+gpi_S+a0_0x4e3b09(0x202)+eoi+a0_0x4e3b09(0x212)+_0x3c4421+a0_0x4e3b09(0x1f8)+_0x5d1e67+a0_0x4e3b09(0x23c)+eoi_S+'\x22;\x20FCNEC='+FCNEC+';\x20compte='+_0x5a8840+';\x20ywm='+_0x5a8840+a0_0x4e3b09(0x237)+_0x16eac3,'referer':''+baseUrl+_0x5efce1+a0_0x4e3b09(0x1fe),'sec-fetch-dest':a0_0x4e3b09(0x211),'sec-fetch-mode':a0_0x4e3b09(0x21d),'sec-fetch-user':'?1','upgrade-insecure-requests':'1'}}),'HEADERS_WRITE_MESSAGE':(_0x41188d,_0x41420a,_0x4af610,_0x589f9c,_0x4ace3b,_0x1e03d5)=>({'headers':{...baseHeaders,'accept':'*/*','Accept-Encoding':a0_0x4e3b09(0x208),'content-type':a0_0x4e3b09(0x228),'cookie':_0x41188d+a0_0x4e3b09(0x241)+_0x41420a+';\x20ywm='+_0x41420a+a0_0x4e3b09(0x246)+gads+a0_0x4e3b09(0x212)+_0x589f9c+a0_0x4e3b09(0x1f8)+_0x4ace3b+a0_0x4e3b09(0x23c)+gads_S+a0_0x4e3b09(0x23e)+gpi+a0_0x4e3b09(0x212)+_0x589f9c+a0_0x4e3b09(0x1f8)+_0x4ace3b+a0_0x4e3b09(0x23c)+gpi_S+a0_0x4e3b09(0x202)+eoi+':T='+_0x589f9c+a0_0x4e3b09(0x1f8)+_0x4ace3b+':S='+eoi_S+a0_0x4e3b09(0x210)+FCNEC+';compte='+_0x41420a+a0_0x4e3b09(0x243)+_0x41420a+a0_0x4e3b09(0x237)+_0x1e03d5,'origin':a0_0x4e3b09(0x247),'referer':a0_0x4e3b09(0x233)+_0x4af610+a0_0x4e3b09(0x1fe),'sec-fetch-dest':a0_0x4e3b09(0x242),'sec-fetch-mode':a0_0x4e3b09(0x216)}})},PATHS={'PATH_INBOX_FILE':a0_0x4e3b09(0x21a),'PATH_MAIL_CONTENT':a0_0x4e3b09(0x203),'PATH_HTML_ID':a0_0x4e3b09(0x22d),'PATH_HTML_SUBJECT':a0_0x4e3b09(0x248),'PATH_HTML_CONTENT':'tests/archives/mailHTML_content.html'},SELECTORS={'S_INPUT_YP':a0_0x4e3b09(0x23b),'S_INPUT_MAIL_GENERATE':a0_0x4e3b09(0x23f),'S_SUBMIT':a0_0x4e3b09(0x21c),'S_FROM':'div.fl\x20>\x20div.md.text.zoom.nw.f24\x20>\x20span.ellipsis.b','S_DATE':a0_0x4e3b09(0x1f6),'S_FROM_ALT':a0_0x4e3b09(0x229),'S_DATE_ALT':'div.fl\x20>\x20div.md.text.zoom.nw.f18\x20>\x20span.ellipsis:last-child','S_MAIL':a0_0x4e3b09(0x239)},REGEXES={'REGEX_LOCATION':/lang="(.*?)"/,'REGEX_YJ':/&yj=([^&]+)&v=/,'REGEX_TOTAL_MAILS':/w\.finrmail\((.*?)\)/,'REGEX_VER':/\/ver\/(\d+\.\d+)\//},ERRORS={'ERROR_MAIL_INVALID':a0_0x4e3b09(0x226),'ERROR_SEARCH_INVALID':a0_0x4e3b09(0x221),'ERROR_LOAD_PAGE':a0_0x4e3b09(0x20e),'ERROR_GET_INBOX':a0_0x4e3b09(0x232),'ERROR_DELETE_INBOX':a0_0x4e3b09(0x235),'ERROR_READ_MESSAGE':'readMessage():\x20Error\x20read\x20message','ERROR_READ_MESSAGE_FORMAT':'readMessage():\x20The\x20format\x20is\x20invalid.\x20Try\x20again\x20with\x20(HTML\x20or\x20TXT)','ERROR_READ_MESSAGE_ATTRIBUTE':a0_0x4e3b09(0x215),'ERROR_READ_MESSAGE_STATUS_410':'readMessage():\x20The\x20message\x20has\x20been\x20deleted\x20or\x20does\x20not\x20exist.\x20Try\x20reviewing\x20the\x20ID','ERROR_WRITE_MESSAGE':a0_0x4e3b09(0x20f),'ERROR_DELETE_MESSAGE':'deleteMessage():\x20Error\x20delete\x20message','ERROR_PARAMETERS_INVALID':a0_0x4e3b09(0x1fd),'ERROR_GET_COOKIES':a0_0x4e3b09(0x23d),'ERROR_GET_VERSION':a0_0x4e3b09(0x238),'ERROR_MISSING_PARAMETERS':a0_0x4e3b09(0x201),'ERROR_GET_TOTAL_MAILS':'Error\x20getting\x20total\x20number\x20of\x20mails','ERROR_GET_YJ':a0_0x4e3b09(0x205),'ERROR_URL_NOT_FOUND':a0_0x4e3b09(0x214),'ERROR_SAVE_HTML':'Error\x20saving\x20HTML\x20file'},NOTIFY={'NOTIFY_EMAIL_NOT_FOUND':_0x4ce0b1=>'The\x20mail\x20with\x20ID\x20['+_0x4ce0b1+']\x20was\x20not\x20found\x20and\x20could\x20not\x20be\x20deleted.','NOTIFY_EMAIL_DELETED_SUCCESS':_0x26aebb=>a0_0x4e3b09(0x218)+_0x26aebb+']\x20has\x20been\x20successfully\x20deleted.','NOTIFY_EMAIL_DELETED_FAILED':_0x1df999=>a0_0x4e3b09(0x20b)+_0x1df999+'].\x20Try\x20again\x20later.','NOTIFY_INBOX_DELETED_SUCCESS':(_0x3136b3,_0x2fa261)=>a0_0x4e3b09(0x244)+_0x3136b3+a0_0x4e3b09(0x22f)+_0x2fa261+a0_0x4e3b09(0x236),'NOTIFY_INBOX_DELETED_FAILED':_0xe11db2=>a0_0x4e3b09(0x230)+_0xe11db2+a0_0x4e3b09(0x20c),'NOTIFY_INBOX_EMPTY':a0_0x4e3b09(0x1fb)},TEST={'TEST_MAIL':'test@yopmail.com','TEST_MAIL_RECEIVER':a0_0x4e3b09(0x1f7)};function a0_0x33fb(_0x5c8eda,_0x8a7191){const _0x305393=a0_0x3053();return a0_0x33fb=function(_0x33fb96,_0x7a7a5b){_0x33fb96=_0x33fb96-0x1f3;let _0x437300=_0x305393[_0x33fb96];return _0x437300;},a0_0x33fb(_0x5c8eda,_0x8a7191);}module[a0_0x4e3b09(0x24a)]=Object[a0_0x4e3b09(0x21b)]({...URLS,...HTTP_CONFIG,...PATHS,...SELECTORS,...REGEXES,...ERRORS,...NOTIFY,...TEST}); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 8c39447..fecc097 100644 --- a/src/core.js +++ b/src/core.js @@ -1 +1 @@ -"use strict";function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}const fs=require("fs"),zlib=require("zlib"),https=require("https"),cheerio=require("cheerio"),constants=require("./constants");class Core{constructor(){_defineProperty(this,"validateSelectAttrEQ",((a,b,c,d,e)=>(b&&0===a(b).length?e.push("Warning - The selector <".concat(b,"> is not found in the html.")):d>a(b).length&&e.push("Warning - The eq(".concat(d,") is greater than the number of elements found in the selector ").concat(b,".")),e))),_defineProperty(this,"getContentBySelectorForTxt",((a,b,c,d,e)=>{let f=[];return e=this.validateSelectAttrEQ(a,b,c,d,e),b||(f+=a(this.constants.S_MAIL).text().replace(/\s+|\n/gm," ").trim()),b&&!d&&a(b).each(((b,c)=>{f.push(a(c).text().trim())})),b&&d&&(f+=a(b).eq(parseInt(d,10)).text().replace(/\s+|\n/gm," ").trim(),!f&&e.push("Warning - No text found with selector <".concat(b,"> and .eq(").concat(d,")"))),{info:e,content:f}})),_defineProperty(this,"getContentBySelectorForHTML",((a,b,c,d,e)=>{let f;if(e=this.validateSelectAttrEQ(a,b,c,d,e),!b)return f=a.html(this.constants.S_MAIL),{info:e,content:f};if(f=(()=>c?void 0!==d&&null!==d?a(b).eq(parseInt(d,10)).attr(c):a(b).map(((b,d)=>a(d).attr(c))).toArray():void 0!==d&&null!==d?a(b).eq(parseInt(d,10)).html():a(b).map(((b,c)=>a.html(c))).toArray())(),!f||Array.isArray(f)&&!f.length){let a="Element not found";a+=" with selector ".concat(b),a+=c?" and attribute ".concat(c):"",a+=void 0===d?"":" and eq ".concat(d),e.push(a)}return{info:e,content:f}})),this.constants=constants,this.cwd=process.cwd()}async request(a,b){let c=2{const c=Buffer.concat(b).toString();return{statusCode:a.statusCode,headers:a.headers,body:c}},f=(a,b,c)=>{const d=a.headers["content-encoding"];let f=a;"gzip"===d?f=a.pipe(zlib.createGunzip()):"deflate"===d&&(f=a.pipe(zlib.createInflate()));const g=[];f.on("data",(a=>g.push(a))),f.on("end",(()=>b(e(a,g)))),f.on("error",(a=>c(a)))},g=((a,b,c)=>{const d=new URL(a);return{hostname:d.hostname,port:443,path:"".concat(d.pathname).concat(d.search),method:b.toUpperCase(),...c}})(b,a,c),h=(a,b)=>new Promise(((c,d)=>{const e=https.request(a,(a=>{f(a,c,d)}));e.on("error",(a=>d(a))),a.body&&e.write(a.body),"POST"===a.method&&b&&e.write(b),e.end()}));try{return await h(g,d)}catch(a){this.handleError({customMessage:"Request Error",error:a})}}async getHttpSettings(){try{const a=await this.request("GET",this.constants.URL_BASE);200!==a.statusCode&&this.handleError({customMessage:this.constants.ERROR_GET_COOKIES});const b=this.loadHTMl(a.body),c=b(this.constants.S_INPUT_YP).val(),d=a.headers["set-cookie"].map((a=>a.split(";")[0])).join("; "),e=a.body.match(this.constants.REGEX_LOCATION)[1],f=a.body.match(this.constants.REGEX_VER)[1],g=await this.request("GET",this.constants.URL_WEBMAIL_JS(f),{headers:{Cookie:d}});200!==g.statusCode&&this.handleError({customMessage:this.constants.ERROR_GET_YJ});const h=g.body.match(this.constants.REGEX_YJ),i=h?h[1]:null,j=this.timeStampInSeconds(),k=this.timeStampInSeconds(),l=this.obtenerYTime(j);return{location:e,version:f,cookie:d,yp:c,yj:i,T:j,RT:k,ytime:l}}catch(a){return this.handleError({customMessage:this.constants.ERROR_GET_COOKIES,error:a}),null}}async detailInbox(a,b,c,d){const{location:e,version:f,cookie:g,yp:h,yj:i,T:j,RT:k,ytime:l}=d,m=15;let n=1,o=!0,p={},q=0,r=[],s={};const t=async(a,b,c,d,e,f,g)=>{let h=constants.URL_INBOX(a,b,c,d,f,g),i=constants.HEADERS_INBOX(e,a,g,j,k,l);const m=await this.request("GET",h,i);return 200!==m.statusCode&&this.handleError({customMessage:constants.ERROR_LOAD_PAGE}),m};b&&0=w||n>=c.LIMIT?o=!1:n+=1}return{mail:"".concat(a,"@yopmail.com"),settings:c,filteredSearch:s,pageCount:Math.ceil(w/m),totalEmails:w,emailsPerPageCount:p,exploredPageCount:q,fetchedEmailCount:r.length,inbox:r}}getDetailInboxFromPage(a,b,c){const d=this.loadHTMl(a),e=d(".m");return e.map(((a,b)=>this.parseEmail(b,c))).toArray().filter((a=>this.shouldIncludeEmail(a,b)))}loadHTMl(a){return cheerio.load(a)}getTotalMails(a){const b=a.match(constants.REGEX_TOTAL_MAILS);let c=0;return b&&(c=b[1].split(",")[0]),+c}saveEmailHTML(a,b,c){let d="".concat(this.cwd,"/").concat(a);fs.existsSync(d)||fs.mkdirSync(d,{recursive:!0}),fs.writeFileSync("".concat(d,"/emailPage_").concat(c,".html"),b,(function(a){if(a)return new Error(a)}))}validateSearch(a){const b=["id","from","subject","timestamp"],c=b.some((b=>Object.keys(a).includes(b)||null));return c||this.handleError({customMessage:this.constants.ERROR_PARAMETERS_INVALID,error:new Error}),Object.keys(a).reduce(((c,d)=>(b.includes(d)&&(c[d]=a[d]),c)),{})}parseEmail(a,b){const c=cheerio.load(a),d=c(a).attr("id"),e=c(a).find(".lmh").text(),f=c(a).find(".lmf").text(),g=c(a).find(".lms").text();return{id:d,from:f,subject:g,timestamp:e,page:b}}shouldIncludeEmail(a,b){return Object.entries(b).every((b=>{let[c,d]=b;return"id"===c?a.id===d:"from"===c?a.from===d:"subject"===c?a.subject===d:!("timestamp"!==c)&&a.timestamp===d}))}obtenerYTime(a){const b=new Date(1e3*a),c=b.getHours(),d=b.getMinutes();return"".concat(c,":").concat(d)}timeStampInSeconds(){return Math.floor(Date.now()/1e3)}simplifyEmail(a){return-1{["html","txt"].includes(b.toLowerCase())||(c.push("Warning - the format ".concat(b," is incorrect, the default format is TXT")),a.format="txt")},h=(a,b,c)=>{const d=null===b||void 0===b?void 0:b.match(/^(.+)\.eq\((\d+)\)$/);if(d){const[,b,c]=d;a.eq=c,a.selector=b}else if(null!==b&&void 0!==b&&b.includes(".eq(")){const[d]=b.split(".eq(");a.selector=d,a.eq=null,c.push('Warning - the ".eq()" value is invalid, the default eq is null')}},i=(a,b,c,d)=>{c&&!b?(d.push("Warning - the attribute requires a selector, the default attribute is null"),a.attribute=null):c&&"string"!=typeof c&&(d.push("Warning - the attribute ".concat(c," is incorrect, the default attribute is empty")),a.attribute=null)},j=(a,b,c)=>{b&&"string"!=typeof b&&(c.push("Warning - the pathToSave ".concat(b," is incorrect, the default pathToSave is empty")),a.pathToSave=null)};return g(a,e,f),((a,b,c)=>{b&&"string"!=typeof b?(c.push("Warning - the selector ".concat(b," is incorrect, the default selector is null")),a.selector=null):h(a,b,c)})(a,b,f),i(a,b,c,f),j(a,d,f),{opt:a,info:f}}handleError(){let{customMessage:b=this.constants.ERROR_LOAD_PAGE,error:a}=0{const f=this.getSettings(b,a,c),g=https.request(f,(a=>{let b=a;const c=a.headers["content-encoding"];"gzip"===c?b=a.pipe(zlib.createGunzip()):"deflate"===c&&(b=a.pipe(zlib.createInflate()));const f=[];b.on("data",(a=>{f.push(a)})),b.on("end",(()=>{const b=Buffer.concat(f),c={statusCode:a.statusCode,headers:a.headers,body:b};d(c)})),b.on("error",(a=>{e(a)}))}));g.on("error",(a=>{e(a)})),g.end()}))}async request(a,b){let c=2{const c=Buffer.concat(b).toString();return{statusCode:a.statusCode,headers:a.headers,body:c}},f=(a,b,c)=>{const d=a.headers["content-encoding"];let f=a;"gzip"===d?f=a.pipe(zlib.createGunzip()):"deflate"===d&&(f=a.pipe(zlib.createInflate()));const g=[];f.on("data",(a=>g.push(a))),f.on("end",(()=>b(e(a,g)))),f.on("error",(a=>c(a)))},g=this.getSettings(b,a,c),h=(a,b)=>new Promise(((c,d)=>{const e=https.request(a,(a=>{f(a,c,d)}));e.on("error",(a=>d(a))),a.body&&e.write(a.body),"POST"===a.method&&b&&e.write(b),e.end()}));try{return await h(g,d)}catch(a){this.handleError({customMessage:"Request Error",error:a})}}async getHttpSettings(){try{const a=await this.request("GET",this.constants.URL_BASE);200!==a.statusCode&&this.handleError({customMessage:this.constants.ERROR_GET_COOKIES});const b=this.loadHTMl(a.body),c=b(this.constants.S_INPUT_YP).val(),d=a.headers["set-cookie"].map((a=>a.split(";")[0])).join("; "),e=a.body.match(this.constants.REGEX_LOCATION)[1],f=a.body.match(this.constants.REGEX_VER)[1],g=await this.request("GET",this.constants.URL_WEBMAIL_JS(f),{headers:{Cookie:d}});200!==g.statusCode&&this.handleError({customMessage:this.constants.ERROR_GET_YJ});const h=g.body.match(this.constants.REGEX_YJ),i=h?h[1]:null,j=this.timeStampInSeconds(),k=this.timeStampInSeconds(),l=this.obtenerYTime(j);return{location:e,version:f,cookie:d,yp:c,yj:i,T:j,RT:k,ytime:l}}catch(a){return this.handleError({customMessage:this.constants.ERROR_GET_COOKIES,error:a}),null}}async detailInbox(a,b,c,d){const{location:e,version:f,cookie:g,yp:h,yj:i,T:j,RT:k,ytime:l}=d,m=15;let n=1,o=!0,p={},q=0,r=[],s={};const t=async(a,b,c,d,e,f,g)=>{let h=constants.URL_INBOX(a,b,c,d,f,g),i=constants.HEADERS_INBOX(e,a,g,j,k,l);const m=await this.request("GET",h,i);return 200!==m.statusCode&&this.handleError({customMessage:constants.ERROR_LOAD_PAGE}),m};b&&0=w||n>=c.LIMIT?o=!1:n+=1}return{mail:`${a}@yopmail.com`,settings:c,filteredSearch:s,pageCount:Math.ceil(w/m),totalEmails:w,emailsPerPageCount:p,exploredPageCount:q,fetchedEmailCount:r.length,inbox:r}}getDetailInboxFromPage(a,b,c){const d=this.loadHTMl(a),e=d(".m");return e.map(((a,b)=>this.parseEmail(b,c))).toArray().filter((a=>this.shouldIncludeEmail(a,b)))}validateSelectAttrEQ=(a,b,c,d,e)=>(b&&0===a(b).length?e.push(`Warning - The selector <${b}> is not found in the html.`):d>a(b).length&&e.push(`Warning - The eq(${d}) is greater than the number of elements found in the selector ${b}.`),e);getContentBySelectorForTxt=(a,b,c,d,e)=>{let f=[];return e=this.validateSelectAttrEQ(a,b,c,d,e),b||(f+=a(this.constants.S_MAIL).text().replace(/\s+|\n/gm," ").trim()),b&&!d&&a(b).each(((b,c)=>{f.push(a(c).text().trim())})),b&&d&&(f+=a(b).eq(parseInt(d,10)).text().replace(/\s+|\n/gm," ").trim(),!f&&e.push(`Warning - No text found with selector <${b}> and .eq(${d})`)),{info:e,content:f}};getContentBySelectorForHTML=(a,b,c,d,e)=>{let f;if(e=this.validateSelectAttrEQ(a,b,c,d,e),!b)return f=a.html(this.constants.S_MAIL),{info:e,content:f};if(f=(()=>c?void 0!==d&&null!==d?a(b).eq(parseInt(d,10)).attr(c):a(b).map(((b,d)=>a(d).attr(c))).toArray():void 0!==d&&null!==d?a(b).eq(parseInt(d,10)).html():a(b).map(((b,c)=>a.html(c))).toArray())(),!f||Array.isArray(f)&&!f.length){let a=`Element not found`;a+=` with selector ${b}`,a+=c?` and attribute ${c}`:"",a+=void 0===d?"":` and eq ${d}`,e.push(a)}return{info:e,content:f}};loadHTMl(a){return cheerio.load(a)}getTotalMails(a){const b=a.match(constants.REGEX_TOTAL_MAILS);let c=0;return b&&(c=b[1].split(",")[0]),+c}saveEmailHTML(a,b,c){let d=`${this.cwd}/${a}`;fs.existsSync(d)||fs.mkdirSync(d,{recursive:!0}),fs.writeFileSync(`${d}/emailPage_${c}.html`,b,(function(a){if(a)return new Error(a)}))}validateSearch(a){const b=["id","from","subject","timestamp"],c=b.some((b=>Object.keys(a).includes(b)||null));return c||this.handleError({customMessage:this.constants.ERROR_PARAMETERS_INVALID,error:new Error}),Object.keys(a).reduce(((c,d)=>(b.includes(d)&&(c[d]=a[d]),c)),{})}parseEmail(a,b){const c=cheerio.load(a),d=c(a).attr("id"),e=c(a).find(".lmh").text(),f=c(a).find(".lmf").text(),g=c(a).find(".lms").text();return{id:d,from:f,subject:g,timestamp:e,page:b}}shouldIncludeEmail(a,b){return Object.entries(b).every((b=>{let[c,d]=b;return"id"===c?a.id===d:"from"===c?a.from===d:"subject"===c?a.subject===d:!("timestamp"!==c)&&a.timestamp===d}))}obtenerYTime(a){const b=new Date(1e3*a),c=b.getHours(),d=b.getMinutes();return`${c}:${d}`}timeStampInSeconds(){return Math.floor(Date.now()/1e3)}simplifyEmail(a){return-1{["html","txt"].includes(b.toLowerCase())||(c.push(`Warning - the format ${b} is incorrect, the default format is TXT`),a.format="txt")},i=(a,b,c)=>{const d=b?.match(/^(.+)\.eq\((\d+)\)$/);if(d){const[,b,c]=d;a.eq=c,a.selector=b}else if(b?.includes(".eq(")){const[d]=b.split(".eq(");a.selector=d,a.eq=null,c.push(`Warning - the ".eq()" value is invalid, the default eq is null`)}},j=(a,b,c,d)=>{c&&!b?(d.push(`Warning - the attribute requires a selector, the default attribute is null`),a.attribute=null):c&&"string"!=typeof c&&(d.push(`Warning - the attribute ${c} is incorrect, the default attribute is empty`),a.attribute=null)},k=(a,b,c)=>{b&&"string"!=typeof b&&(c.push(`Warning - the pathToSave ${b} is incorrect, the default pathToSave is empty`),a.pathToSave=null)},l=(a,b,c)=>{"boolean"!=typeof b&&(c.push(`Warning - the saveAttachment ${b} is incorrect, the default saveAttachment is false`),a.saveAttachment=!1)};return h(a,f,g),((a,b,c)=>{b&&"string"!=typeof b?(c.push(`Warning - the selector ${b} is incorrect, the default selector is null`),a.selector=null):i(a,b,c)})(a,b,g),j(a,b,c,g),k(a,d,g),l(a,e,g),{opt:a,info:g}}handleError(){let{customMessage:b=this.constants.ERROR_LOAD_PAGE,error:a}=0{fs.writeFileSync(`${d}/${b}`,a.body)}))}}module.exports=Core; \ No newline at end of file