Esempio n. 1
0
 stream.once('end', function() {
   imap.seq.addFlags(seqno,'DELETED', function(err) {
     //console.log('addFlags err: ',err);
   });
   console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
   var studentName = nameRegex.exec(Imap.parseHeader(buffer).from[0]) || [];
   var studentEmail = emailRegex.exec(Imap.parseHeader(buffer).from[0]) || [];
   student = studentName[1] || studentEmail[1] || studentDefault;
   console.log('From: ',student);
 });
Esempio n. 2
0
					mailparser.on("end", function(mail) {
						var from = Imap.parseHeader(buffer)["from"];
						from = from.toString().split("<")[1];
						from = from.toString().split(">")[0];
						console.log("----------------from:" + from);
						fs.writeFile('msg-' + seqno + '-body.html', mail.html, function(err) {
							if (err)
								throw err;
							console.log(seqno + 'saved!');

							htmlToText.fromFile(path.join(__dirname, 'msg-' + seqno + '-body.html'), {
								tables : ['#invoice', '.address']
							}, function(err, text) {
								if (err)
									return console.error(err);
								fs.writeFile('msg-' + seqno + '-body.txt', text, function(err) {
									if (err)
										throw err;
									console.log(seqno + 'text saved!');
								});

								fs.unlink('msg-' + seqno + '-body.html', function(e) {
									if (e) {
										console.log(e);
									} else
										console.log('msg-' + seqno + '-body.html' + "delete succeed");
								});

							});
						});
					});
Esempio n. 3
0
 streamToString(body_stream, function(error, string){
     if (error){return _cb(error);}
     switch (body_info.which){
         case 'HEADER': header = Imap_parseHeader(string); break;
         case 'TEXT': text = string; break;
         default: _cb(new Error('did not recognize body type'));
     }
 });
Esempio n. 4
0
 stream.on('end', function() {
     if (info.which !== 'TEXT') {
         pay.from = Imap.parseHeader(buffer).from[0];
         pay.topic = Imap.parseHeader(buffer).subject[0];
         pay.date = Imap.parseHeader(buffer).date[0];
     } else {
         var parts = buffer.split("Content-Type");
         for (var p in parts) {
             if (parts[p].indexOf("text/plain") >= 0) {
                 pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim();
             }
             if (parts[p].indexOf("text/html") >= 0) {
                 pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim();
             }
         }
         //pay.body = buffer;
     }
 });
						stream.once('end', () => {
							if (info.which === '1') {
								email.body = bodyBuffer;
							} else {
								// parse headers
								email.headers = IMAP.parseHeader(headerBuffer);

								email.headers.to = email.headers.to[0];
								email.headers.date = email.headers.date[0];
								email.headers.from = email.headers.from[0];
							}
						});
Esempio n. 6
0
				stream.on('end', () => {
					let headers = Imap.parseHeader(buffer);
					let subj = headers.subject[0];
					let date = Date.parse(headers.date[0]);

					let now = Date.now();
					let diff = (now - date) / 1000;

					debug('new message: [%s] "%s" {#%s} [%s secs]', this.config.name, subj, msg_uid, diff);
					if(Math.abs(diff) < 60) {
						if(this.handle_cb(subj)) {
							this.deleteMessage(msg_uid);
						}
					} else {
						debug('**** time diff too large: [%s] %s min => ignoring this message...', this.config.name, (diff / 60) | 0);
					}
				});
Esempio n. 7
0
 stream.on('end', function() {
     if (info.which !== 'TEXT') {
         var head = Imap.parseHeader(buffer);
         if (head.hasOwnProperty("from")) { pay.from = head.from[0]; }
         if (head.hasOwnProperty("subject")) { pay.topic = head.subject[0]; }
         if (head.hasOwnProperty("date")) { pay.date = head.date[0]; }
         pay.header = head;
     } else {
         var parts = buffer.split("Content-Type");
         for (var p = 0; p < parts.length; p++) {
             if (parts[p].indexOf("text/plain") >= 0) {
                 pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim();
             }
             else if (parts[p].indexOf("text/html") >= 0) {
                 pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim();
             } else {
                 pay.payload = parts[0];
             }
         }
         //pay.body = buffer;
     }
 });
Esempio n. 8
0
 stream.once('end', function(){
   headerBuffer = Imap.parseHeader(headerBuffer);
 })
Esempio n. 9
0
 stream.once('end', function()
 {
   notes.push({header: header, body: body, parsed: Imap.parseHeader(header)});
 });
Esempio n. 10
0
 stream.on('end', function() {
   console.log('INFO', info);
   messageList[seqno] = IMAP.parseHeader(headerBuffer.join(''));
   headerBuffer = '';
 });
Esempio n. 11
0
                stream.once('end', function() {
                    var mailheader = eval('(' + inspect(Imap.parseHeader(buffer)) + ')');
                    var subject = mailheader.subject;
                    if (/Flight Status Message/.test(subject)) {

                        var mailinfo = buffer.substring(buffer.indexOf('<!DOCTYPE'), buffer.indexOf('</html>') + 8);

                        var $ = cheerio.load(mailinfo);

                        var status,flightnum;

                        $('td.status').each(function(i,e){
                            if (i == 0) {
                                var temp = $(e).text().replace(/[\n\r\t]+/g,'').replace(/[\s]{2,}/g,'');
                                var a = temp.indexOf('Singapore Airlines');
                                var b = temp.indexOf('Status');
                                var c = temp.indexOf('Event');
                                if (a > -1 && b > a && c > b) {
                                    flightnum = temp.substring(a + 18, b).replace('#','').replace(/[\s]+/g,'');
                                    status = temp.substring(b + 6, c).replace(':','').replace(/[\s]+/g,'');;
                                }
                                console.log('flightnum is : ' + flightnum);
                                console.log('status is : ' + status);
                                return false;
                            }
                        });

                        var flightdate = '',
                            sceduldeptime = '',
                            dely = '';

                        //航班日期
                        $('td.status_caps').each(function(i,e){
                            if (i == 0) {
                                var temp = $(e).text().replace(/[\n\r\t]+/g,'').replace(/[\s]{2,}/g,'').replace('min','');
                                if (/DEPARTS/.test(temp)) {
                                    flightdate = temp.substring(temp.indexOf(':')+2,temp.indexOf('('));
                                }
                                console.log('flightdate is : ' + flightdate);
                                return false;
                            }

                        });

                        //预计起飞时间
                        $('td.schedule_data').each(function(i,e){
                            if (i == 0) {
                                sceduldeptime = $(e).text().replace(/[\n\r\t]+/g,'').replace(/[\s]{2,}/g,'');
                                console.log('sceduldeptime is : ' + sceduldeptime);
                                return false;
                            }
                        });

                        //延迟时间
                        $('td.delay').each(function(i,e){
                            if (i == 0) {
                                dely = $(e).text().replace(/[\n\r\t]+/g,'').replace(/[\s]{2,}/g,'').replace('min','');
                                console.log('dely is : ' + dely);
                                return false;
                            }
                        });

                        sceduldeptime = flightdate + sceduldeptime;

                        sceduldeptime = getFullDate(sceduldeptime);
                        console.log('sceduldeptime is : ' + sceduldeptime);



                        var realdeptime = getDeptime(sceduldeptime, dely);
                        console.log('realdeptime is : ' + realdeptime);
                    }
                });
Esempio n. 12
0
    msg.once('end', function() {
      debug( prefix + "Message - end: " );

      if( hadErrInMessage || hadErrInBody ) return;

      // Setting fullMessage
      fullImapMessage.headers = Imap.parseHeader( messageRawBody );
      fullImapMessage.uid = attributes.uid;

      debug("TEMPORARY MESSAGE: ", fullImapMessage );

      var bodyParts = findBodyParts( attributes.struct );

      // FETCH BODY PARTS

      // At this point, we are missing "text" and "html" in fullImapMessage.
      // It should be easy to get it

      var partIDs = [];

      if( bodyParts.html ) partIDs.push( { type: 'bodyHtml', partID: bodyParts.html.partID } );
      if( bodyParts.text ) partIDs.push( { type: 'bodyText', partID: bodyParts.text.partID } );

      async.eachSeries(
        partIDs,
        function( partID, cb ){

          debug("ABOUT TO FETCH PART:");
          fetchMessagePart( imap, fullImapMessage.uid, partID.partID, function( err, part ){
            if( err ) return cb( err );

            debug("PART FETCHED");

            fullImapMessage[ partID.type ] = mimelib.decodeQuotedPrintable( part.body );
            cb( null );
          })
        },
        function( err ){
          if( err ) return done( err );


          // FETCH ATTACHMENT PARTS

          var attachmentPartsInStruct = findAttachments( attributes.struct );

          debug("Attachment parts in struct: %o", attachmentPartsInStruct );

          async.eachSeries(
            attachmentPartsInStruct,
            function( partInStruct, cb ){

              // Get the filename, Use DeepObject as it's quite deep into partInStruct
              var fileName = DeepObject.get( partInStruct, 'disposition.params.filename');

              // Get the size limit from the configuration
              var sizeLimit = hotplate.config.get('hotCoreTransport.activeTransports.email-default.attachmentSizeLimit');


              debug("sizeLimit is: ", sizeLimit );
;
              debug("Comparing: %d && %d > %d", sizeLimit, partInStruct.size, sizeLimit );

              // If it's too big, do not download it
              if( sizeLimit && partInStruct.size > sizeLimit ){
                // The next log line is pointless as the message hasn't been created yet, and it
                // would end up in the "generic" transport log...
                // logLine( config, null, null, 1, "Attachment " + fileName + " wasn't fetched as it was too big --  " + partInStruct.size + " bytes against a " + sizeLimit + "limit" );

                // Make up the attachment object
                var p = {
                  id: partInStruct.partID,
                  mimeType: partInStruct.type+ '/' + partInStruct.subtype,
                  retrieved: false,
                  size: partInStruct.size,
                };
                if( fileName ) p.fileName = fileName;
                if( partInStruct.id ) p.embeddedId = partInStruct.id;

                // Add the object to the attachment array
                fullImapMessage.attachments.push( p );

                return cb( null );
              }

              debug("ABOUT TO FETCH ATTACHMENT PART %o:", partInStruct);
              fetchMessagePart( imap, fullImapMessage.uid, partInStruct.partID, function( err, downloadedPart ){
                if( err ) return cb( err );

                //downloadedPart.body = downloadedPart.body.substr( 0, 400 );
                debug("ATTACHMENT PART FETCHED:", downloadedPart );

                // Make up the attachment object
                var p = {
                  id: partInStruct.partID,
                  data: downloadedPart.body,
                  mimeType: partInStruct.type+ '/' + partInStruct.subtype,
                  size: partInStruct.size,
                  retrieved: true,
                };
                if( fileName ) p.fileName = fileName;
                if( partInStruct.id ) p.embeddedId = partInStruct.id;

                // Add the object to the attachment array
                fullImapMessage.attachments.push( p );
                cb( null );
              })
            },
            function( err ){
              if( err ) return done( err );

              done( null, fullImapMessage );
            }
          );

        }
      );

    })
Esempio n. 13
0
						stream.once('end', function() {
							
							mails = Imap.parseHeader(buffer);
							socketUsers[sessionID].emit('mail', { 'mail' : mails, 'seqno': seqno });
						//console.log(mails);
						});
Esempio n. 14
0
 stream.once( 'end', function() {
   emails.push(Imap.parseHeader(buffer));
   // console.log( ( prefix + 'Parsed header: %s' ), obj );
 });
Esempio n. 15
0
        stream.once('end', function() {
			var header=Imap.parseHeader(buffer);
			//console.log('Parsed header: %s', inspect(header));
			callback && callback(header);
        });
Esempio n. 16
0
 stream.once('end', function() {
   if (info.which !== 'TEXT')
     console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
   else
     console.log(prefix + 'Body [%s] Finished', inspect(info.which));
 });
Esempio n. 17
0
 stream.once('end', function() {
   console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
 });
Esempio n. 18
0
 stream.once('end', function() {
     var headers = Imap.parseHeader(buffer);
     mail.push(headers);
 });