简体   繁体   English

Gmail:同步收件箱(已禁用IMAP和POP3)

[英]Gmail: Sync Inbox (IMAP & POP3 disabled)

Problem 问题

There is a need to read my sent items from my gmail account between two dates and that follows a similar text pattern on the subject, this is all in order to segregate the sent items that has been answered (stored in a excel file) and re-send one reminder to those that hasn't answered. 有必要在两个日期之间从我的gmail帐户中读取我的已发送邮件,并且在主题上遵循类似的文本模式,所有这些都是为了隔离已答复的已发送邮件(存储在excel文件中)并重新-向未回答的人发送提醒。

Real World 真实世界

The problem described above seems to be easy to handle and a good task to perform with the usage of a scripting language, except for the statement below: 上面描述的问题似乎很容易处理,并且使用脚本语言可以很好地完成任务,以下语句除外:

  • IMAP & POP3 are disabled from my account. 我的帐户已禁用IMAP和POP3。

So, the IT folks of the place that I work decided to disable IMAP & POP3 from every single account of the company. 因此,我工作地点的IT人员决定从公司的每个帐户中禁用IMAP和POP3。 Believe it or not this is for a good reason, In order to avoid the usage of an email client (in this case MS Outlook) and save some money --- I've always believed in open source ---. 信不信由你,这是有充分的理由的,为了避免使用电子邮件客户端(在本例中为MS Outlook)并节省一些钱--- 我一直相信开源 ---。

Then, I was wondering on How would it be possible to syncronize the inbox of my gmail account knowing that the company that I work had disabled both IMAP & POP3. 然后,我想知道如何才能同步我的gmail帐户的收件箱,因为我工作的公司同时禁用了IMAP和POP3。

But SMTP...? 但是SMTP ...?

As far as I know SMTP is only for sending email but not for retrieving them. 据我所知,SMTP仅用于发送电子邮件,而不用于检索电子邮件。

What I've tried? 我尝试了什么?

Being a little bit stubborn and blinded by the idea of avoiding the usage of Sockets in order to accomplish this ridiculous task, I've ended up playing with the following ruby gems: 为避免完成此荒谬的任务而避免使用Sockets的想法使我有些固执和蒙蔽,我最终使用了以下宝石红宝石:

Above two gems are awesome for sending/retrieving emails, but only if your account have IMAP or POP3 enabled. 以上两个gem非常适合发送/检索电子邮件,但前提是您的帐户启用了IMAP或POP3。

Facts 事实

How come that my devices can syncronize my inbox even if IMAP & POP3 are disabled. 即使禁用了IMAP和POP3,我的设备如何能够同步收件箱。

  • The Android device, syncs via it's gmail application. Android设备通过其gmail应用程序进行同步。
  • The iOS device, syncs via Microsoft Exchange Server. iOS设备通过Microsoft Exchange Server进行同步。

Questions 问题

  • Is there any other way to implement this and avoiding the use of Sockets (for web-crawling my sent items) at the same time? 还有其他方法可以实现此目的,并避免同时使用Socket(用于对我发送的项目进行网络爬网)吗?

Without IMAP you're really left with no options. 没有IMAP,您将无可奈何。 I don't see a way to do it without making some kind of screen scraping bot, and then parsing that information is going to be a huge mess. 如果没有制作某种屏幕抓取机器人,然后解析该信息将是一团糟,我看不出有办法做到这一点。 Is there a reason you can't use the label and filter system built into Gmail to make a label with the emails you're after? 您是否有理由无法使用Gmail内置的标签和过滤器系统来为收到的电子邮件添加标签?

Solution

In order to avoid the usage of sockets for this assignment I've tried to build an Chrome extension/apps, but this would become as riduculous as using sockets. 为了避免在此任务中使用套接字,我尝试构建一个Chrome扩展程序/应用程序,但这会变得与使用套接字一样繁琐。

Thanks god Google Apps Script exists. 谢谢上帝Google Apps脚本的存在。

Code

var VENDOR_NAME_INDEX = 0;
var CONTACTS_INDEX = VENDOR_NAME_INDEX + 1;
var HAS_REPLIED_INDEX = CONTACTS_INDEX + 1;
var COMMENTS_INDEX = HAS_REPLIED_INDEX + 1;

var VENDORS_SPREADSHEET_URL = "https://docs.google.com/a/jabil.com/spreadsheet/ccc?key=0Aj7MWNXx-gzsdHJQbGhQZUVkMjBFeVNZX0dXdDZjYWc#gid=0";
var VENDORS_GMAIL_QUERY = 'in:sent has:attachment after:2013/06/26 before:2013/06/28 subject: "*Jabil CUU /// Shipping Letter*"';

// http://flesler.blogspot.mx/2008/11/fast-trim-function-for-javascript.html
String.prototype.trimLeft = function() {
  var pivot = -1;
  while (this.charCodeAt(++pivot) < 33);
  return this.slice(pivot, this.length);
}

// http://flesler.blogspot.mx/2008/11/fast-trim-function-for-javascript.html
String.prototype.trimRight = function() {
  var pivot = this.length;
  while (this.charCodeAt(pivot--) < 33);
  return this.slice(0, pivot);
}

vendors = [];
function processSentItems() {
  var threads = GmailApp.search(VENDORS_GMAIL_QUERY);  
  var ss = SpreadsheetApp.openByUrl(VENDORS_SPREADSHEET_URL);

  var data = ss.getDataRange();
  var rows = data.getNumRows();
  var values = data.getValues();

  for (var i = 0; i < rows; ++i) {
    var row = values[i];

    var vendor = row[VENDOR_NAME_INDEX];
    var contacts = row[CONTACTS_INDEX];
    var replied_back = row[HAS_REPLIED_INDEX];
    var comments = row[COMMENTS_INDEX];

    vendors.push({
      name: vendor,
      contacts: contacts,
      replied_back: replied_back,
      comments: comments
    });

  }

  threads.forEach(function(thread) {
    var id = thread.getId();
    var subject = thread.getFirstMessageSubject();
    var vendorName = subject.split("-")[0];

    vendorName = vendorName.trimLeft();
    vendorName = vendorName.trimRight();

    var vendor = getVendorByName(vendorName);

    if (typeof vendor == "object") {
      if (vendor.replied_back.toLowerCase() != "yes") {
        thread.replyAll("Friendly reminder...")
      }
    }
  });

};

function getVendorByName(vendorName) {
  for (var i = 0; i < vendors.length; ++i) {
    if (vendors[i].name == vendorName) {
      return vendors[i];
    }
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM