Browse files

added fetchFlags method

  • Loading branch information...
1 parent c86f0a0 commit 9dd39d4bd0467783bedeb824f7ecc206b4acf771 Andris Reinman committed Nov 12, 2012
Showing with 60 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +9 −0 README.md
  3. +49 −0 lib/client.js
  4. +1 −1 package.json
View
1 .gitignore
@@ -1,2 +1,3 @@
node_modules
.DS_Store
+tools/log.txt
View
9 README.md
@@ -299,6 +299,15 @@ automatically marked as read (\Seen flag is set) when the message is fetched.
You can add and remove message flags like `\Seen` or `\Answered` with `client.addFlags()` and `client.removeFlags()`
+**List flags**
+
+ client.fetchFlags(uid, callback)
+
+Where
+
+ * **uid** is the message identifier
+ * **callback** *(error, flags)* is the callback to run, gets message flags array as a parameter
+
**Add flags**
client.addFlags(uid, flags, callback)
View
49 lib/client.js
@@ -1747,6 +1747,55 @@ IMAPClient.prototype.removeFlags = function(uid, flags, callback){
};
/**
+ * Fetches flags for selected message
+ *
+ * @param {Number} uid Message identifier
+ * @param {Function} callback Callback function to run with the flags array
+ */
+IMAPClient.prototype.fetchFlags = function(uid, callback){
+ uid = Number(uid) || 0;
+
+ if(!uid){
+ if(typeof callback == "function"){
+ callback(new Error("Invalid UID value"));
+ }
+ return;
+ }
+
+ if(this._currentState != this.states.SELECTED){
+ if(typeof callback == "function"){
+ callback(new Error("No mailbox selected"));
+ }
+ return;
+ }
+
+ this._send("UID FETCH "+uid+":"+uid+" (FLAGS)", (function(status){
+ this._collectMailList = false;
+
+ if(typeof callback != "function"){
+ return;
+ }
+
+ if(typeof callback == "function"){
+ if(status == "OK"){
+ if(!this._mailList.length){
+ callback(null, null);
+ }else{
+ callback(null, this._mailList[0].flags || []);
+ }
+ }else{
+ callback(new Error("Error fetching message flags"));
+ }
+ }
+
+ }).bind(this),
+ (function(){
+ this._collectMailList = true;
+ this._mailList = [];
+ }).bind(this));
+};
+
+/**
* Fetches envelope object for selected message
*
* @param {Number} uid Message identifier
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "inbox",
- "version": "0.1.26",
+ "version": "0.1.27",
"author" : "Andris Reinman",
"maintainers":[
{

0 comments on commit 9dd39d4

Please sign in to comment.