Guest User

Untitled

a guest
Aug 3rd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. /*
  2. *
  3. * Copyright (C) 2011, The Locker Project
  4. * All rights reserved.
  5. *
  6. * Please see the LICENSE file for more information.
  7. *
  8. */
  9. //testing for the IMAP connector against a live IMAP server
  10.  
  11. var async = require('async'),
  12. util = require('util'),
  13. ImapConnection = require('imap').ImapConnection;
  14.  
  15. process.on('uncaughtException',function(error){
  16. console.error(error);
  17. console.error(error.stack);
  18. });
  19.  
  20. var auth = {
  21. username: '***',
  22. password: '***',
  23. host: 'imap.gmail.com',
  24. port: '993',
  25. secure: true
  26. // , debug: function(msg) {
  27. // console.log(msg);
  28. // }
  29. };
  30.  
  31. async.series({
  32. connect: function(callback) {
  33. console.log('connect');
  34. imap = new ImapConnection(auth);
  35. imap.connect(function(err) {
  36. callback(err, 'connect');
  37. });
  38. },
  39. openbox: function(callback) {
  40. console.log('openbox');
  41. imap.openBox('INBOX', true, function(err, msg) {
  42. callback(err, 'openbox');
  43. });
  44. },
  45. test334: function(callback) {
  46. fetch('334', function(err, msg) {
  47. callback(err, msg);
  48. });
  49. },
  50. test80: function(callback) {
  51. fetch('80', function(err, msg) {
  52. callback(err, msg);
  53. });
  54. },
  55. test47: function(callback) {
  56. fetch('47', function(err, msg) {
  57. callback(err, msg);
  58. });
  59. },
  60. logout: function(callback) {
  61. console.log('logout');
  62. imap.logout(function(err) {
  63. callback(err, 'logout');
  64. });
  65. }
  66. },
  67. function(err, results) {
  68. if (err) {
  69. console.error(err);
  70. }
  71. console.log(util.inspect(results));
  72. });
  73.  
  74.  
  75. function fetch(uid, callback) {
  76. console.log('fetching uid: ' + uid);
  77. var headerFetch = imap.fetch([uid], { request: { headers: true } });
  78.  
  79. headerFetch.on('message', function(headerMsg) {
  80. headerMsg.on('end', function() {
  81. var bodyFetch = imap.fetch(headerMsg.id, { request: { headers: false, body: true } });
  82.  
  83. bodyFetch.on('message', function(bodyMsg) {
  84. console.log('bodyFetch.on(message)');
  85. bodyMsg.on('data', function(chunk) {
  86. console.log('bodyMsg.on(data)');
  87. });
  88. bodyMsg.on('end', function() {
  89. console.log('bodyMsg.on(end)');
  90. });
  91. });
  92. bodyFetch.on('end', function() {
  93. console.log('bodyFetch.on(end)');
  94. callback(null, 'fetch');
  95. });
  96. });
  97. });
  98. }
Add Comment
Please, Sign In to add comment