Permalink
Browse files

Code maintenance, added first IMAP test with Hoodiecrow

  • Loading branch information...
1 parent 21eda77 commit 1ee74918d301203790b48748894f9611a0512d06 @andris9 andris9 committed Nov 28, 2013
View
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -16,7 +16,7 @@ client.on("connect", function(){
client.openMailbox("[Gmail]/Sent Mail", function(error, mailbox){
if(error) throw error;
-
+
client.storeMessage("From: andris@node.ee\r\n"+
"To: andris@kreata.ee\r\n"+
"Message-Id: 1234\r\n"+
@@ -25,13 +25,13 @@ client.on("connect", function(){
"Tere tere 2!", ["\\Seen"], console.log);
});
-
+
// on new messages, print to console
client.on("new", function(message){
console.log("New message:");
console.log(util.inspect(message, false, 7));
-
+
client.createMessageStream(message.UID).pipe(process.stdout, {end: false});
-
+
});
});
View
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -16,18 +16,18 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
client.listMessages(-1, function(error, messages){
messages.forEach(function(message){
console.log("Message")
console.log(message);
-
+
client.copyMessage(message.UID, "[Gmail]/Saadetud kirjad", function(error){
console.log(arguments);
})
})
})
});
-
+
});
View
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -16,7 +16,7 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
client.listMessages(-1, function(error, messages){
messages.forEach(function(message){
console.log("Message")
View
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -17,11 +17,11 @@ var client = inbox.createConnection(false, "imap.gmail.com", {
client.connect();
client.on("connect", function(){
-
+
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
-
+
+
});
-
+
});
View
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -16,18 +16,18 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
client.listMessages(-1, function(error, messages){
messages.forEach(function(message){
console.log("Message")
console.log(message);
-
+
client.moveMessage(message.UID, "[Gmail]/Saadetud kirjad", function(error){
console.log(arguments);
})
})
})
});
-
+
});
@@ -1,7 +1,7 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -27,22 +27,22 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
// List newest 10 messages
client.listMessages(-10, function(err, messages){
messages.forEach(function(message){
console.log(message.UID+": "+message.title);
});
});
-
+
});
-
+
// on new messages, print to console
client.on("new", function(message){
console.log("New message:");
console.log(util.inspect(message, false, 7));
-
+
client.createMessageStream(message.UID).pipe(process.stdout, {end: false});
-
+
});
});
@@ -1,6 +1,6 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -25,22 +25,22 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
// List newest 10 messages
client.listMessages(-10, function(err, messages){
messages.forEach(function(message){
console.log(message.UID+": "+message.title);
});
});
-
+
});
-
+
// on new messages, print to console
client.on("new", function(message){
console.log("New message:");
console.log(util.inspect(message, false, 7));
-
+
client.createMessageStream(message.UID).pipe(process.stdout, {end: false});
-
+
});
});
View
@@ -1,7 +1,7 @@
var inbox = require(".."),
util = require("util");
-
+
var client = inbox.createConnection(false, "imap.gmail.com", {
secureConnection: true,
auth:{
@@ -29,22 +29,22 @@ client.on("connect", function(){
client.openMailbox("INBOX", function(error, mailbox){
if(error) throw error;
-
+
// List newest 10 messages
client.listMessages(-10, function(err, messages){
messages.forEach(function(message){
console.log(message.UID+": "+message.title);
});
});
-
+
});
-
+
// on new messages, print to console
client.on("new", function(message){
console.log("New message:");
console.log(util.inspect(message, false, 7));
-
+
client.createMessageStream(message.UID).pipe(process.stdout, {end: false});
-
+
});
});
View
@@ -1,3 +1,5 @@
+"use strict";
+
/**
* @fileOverview Provides an simple API for IMAP mailbox access
* @author Andris Reinman
@@ -856,10 +858,11 @@ IMAPClient.prototype._handlerTaggedLogin = function(status){
}
}else{
if(this._xoauth2 && this._xoauth2UntaggedResponse && this._xoauth2RetryCount && this._xoauth2RetryCount < 3){
- this._xoauth2.generateToken((function(err, token){
+ this._xoauth2.generateToken((function(err){
+ var error;
if(err){
if(typeof err != "object"){
- var error = new Error(err.toString());
+ error = new Error(err.toString());
}else{
error = err;
}
@@ -884,21 +887,17 @@ IMAPClient.prototype._handlerTaggedLogin = function(status){
* Handle ID command. We don't reaaly care if the ID succeeded or
* not as it is just some informational data. If it failed we still might be
* able to access the mailbox
- *
- * @param {String} status If "OK" then the command succeeded
*/
-IMAPClient.prototype._handlerTaggedId = function(status){
+IMAPClient.prototype._handlerTaggedId = function(){
this._postReady();
};
/**
* Handle CONDSTORE command. We don't reaaly care if the CONDSTORE succeeded or
* not as it is just some informational data. If it failed we still might be
* able to access the mailbox
- *
- * @param {String} status If "OK" then the command succeeded
*/
-IMAPClient.prototype._handlerTaggedCondstore = function(status){
+IMAPClient.prototype._handlerTaggedCondstore = function(){
var clientData = {
name: X_CLIENT_NAME
};
@@ -1146,8 +1145,8 @@ IMAPClient.prototype._handlerUntaggedIdle = function(){
* Handle search responses, not yet implemented
* TODO: andle search responses
*/
-IMAPClient.prototype._handlerUntaggedSearch = function(list){
- //console.log(list);
+IMAPClient.prototype._handlerUntaggedSearch = function(){
+ return false;
};
/**
@@ -1159,7 +1158,6 @@ IMAPClient.prototype._handlerUntaggedFetch = function(list){
var envelope = (list || [])[3] || [],
envelopeData = this._formatEnvelope(envelope),
nextUID = Number(this._selectedMailbox.UIDNext) || 0,
- nextUID = Number(this._selectedMailbox.UIDNext) || 0,
currentUID = Number(envelopeData.UID) || 0;
if(!nextUID || nextUID <= currentUID){
@@ -1171,7 +1169,7 @@ IMAPClient.prototype._handlerUntaggedFetch = function(list){
}
// emit as new message
- if(this._checkForNewMail){
+ if(nextUID && nextUID <= currentUID && this._checkForNewMail){
this.emit("new", envelopeData);
}
};
@@ -1196,9 +1194,11 @@ IMAPClient.prototype._postCapability = function(){
if(this._capabilities.indexOf("AUTH=XOAUTH2")>=0 && this._xoauth2){
this._xoauth2.getToken((function(err, token){
+ var error;
+
if(err){
if(typeof err != "object"){
- var error = new Error(err.toString());
+ error = new Error(err.toString());
}else{
error = err;
}
@@ -1225,7 +1225,7 @@ IMAPClient.prototype._postCapability = function(){
};
}
- if(['400', '401'].indexOf((data.status || "").toString().trim())>=0){
+ if(['400', '401'].indexOf((data.status || "").toString().trim())>=0){
this._xoauth2RetryCount = (this._xoauth2RetryCount || 0) + 1;
}
@@ -1302,7 +1302,7 @@ IMAPClient.prototype._formatEnvelope = function(envelopeData){
return null;
}
- var dataObject = {}, lastKey = false, headers, i, len;
+ var dataObject = {}, lastKey = false, i, len;
for(i=0, len = envelopeData.length; i<len; i++){
if(!lastKey){
@@ -1330,8 +1330,8 @@ IMAPClient.prototype._formatEnvelope = function(envelopeData){
message.xGMThreadId = dataObject["X-GM-THRID"];
}
- if(dataObject["MODSEQ"]){
- message.modSeq = Number(dataObject["MODSEQ"]);
+ if(dataObject.MODSEQ){
+ message.modSeq = Number(dataObject.MODSEQ);
}
var messageTypes = [],
@@ -2088,7 +2088,7 @@ IMAPClient.prototype.deleteMessage = function(uid, callback){
return;
}
- this.addFlags(uid, "\\Deleted", (function(error, flags){
+ this.addFlags(uid, "\\Deleted", (function(error){
if(error){
return callback(error);
}
@@ -2190,7 +2190,7 @@ IMAPClient.prototype.getMailbox = function(path, callback){
*/
IMAPClient.prototype.idle = function(){
if(this._capabilities.indexOf("IDLE")>=0){
- this._send("IDLE", (function(status){
+ this._send("IDLE", (function(){
this.idling = false;
this._idleEnd = false;
}).bind(this), (function(){
@@ -2203,7 +2203,7 @@ IMAPClient.prototype.idle = function(){
console.log("WARNING: Server does not support IDLE, fallback to NOOP");
}
this._idleTimer = setTimeout((function(){
- this._send("NOOP", (function(status){
+ this._send("NOOP", (function(){
this.nooping = false;
}).bind(this), (function(){
this.nooping = true;
View
@@ -1,3 +1,5 @@
+"use strict";
+
/**
* @fileOverview Provides a parser for IMAP line based commands
* @author Andris Reinman
@@ -423,4 +425,3 @@ IMAPLineParser.prototype._nodeWalker = function(branch, local){
}
}
};
-
Oops, something went wrong.

0 comments on commit 1ee7491

Please sign in to comment.