【问题标题】:get message id/unique id of a mail in gmail contextual gadget在 gmail 上下文小工具中获取邮件的消息 ID/唯一 ID
【发布时间】:2014-05-18 14:10:07
【问题描述】:

我正在尝试编写 GMAIL 上下文小工具。 我已经准备好所有的构建块(服务、小工具、manifest.repositories...) 基本的 hello world 工作正常。

为了简化,让我们说,“我的小部件中有一个标记为收藏”功能

我需要(在我的 SQL 数据库中)针对一些标记为收藏的邮件存储一些对象。

当邮件打开时,我的小部件将加载,现在我想对我的数据库进行 ajax 调用并检查“此特定邮件”是否是最喜欢的邮件。

问题:我只需要在我的 java 脚本中使用唯一的消息 id,以便任何用户将电子邮件标记为收藏。我会将唯一的消息 ID 存储在我的数据库的收藏列表中。

清单


<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">

<!-- Support info to show in the marketplace & control panel -->
<Support>
<!-- URL for application setup as an optional redirect during the install -->
<Link rel="setup" href="https://www.google.com" />

<!-- URL for application configuration, accessed from the app settings
 page in the control panel -->
<Link rel="manage" href="https://www.google.com" />

<!-- URL explaining how customers get support. -->
<Link rel="support" href="https://www.google.com" />

<!-- URL that is displayed to admins during the deletion process,
 to specify policies such as data retention, how to claim accounts, etc. -->
<Link rel="deletion-policy" href="https://www.google.com" />
</Support>

<!-- Name and description pulled from message bundles -->
<Name>HelloWorld</Name>
<Description>A simple Hello World application for testing
Gmail contextual gadgets</Description>

<!-- Show this link in Google's universal navigation for all users -->
<Extension id="navLink" type="link">
<Name>HelloWorld</Name>
<Url>http://www.google.com</Url>
</Extension>

<!-- Declare our OpenID realm so our app is white listed -->
<Extension id="realm" type="openIdRealm">
<Url>http://_example.com_</Url>
</Extension>

<!-- EXTRACTOR -->

<Extension id="HelloWorldExtractor" type="contextExtractor">
<Name>Hello World</Name>
<Url>google.com:HelloWorld</Url>
<!-- Uncomment this Param to apply a filter to the extractor's
default output. The example regexp below makes the match case sensitive.
<Param name="hello" value="H[a-z]* W[a-z]*"/> -->
<Triggers ref="HelloWorldGadget"/>
<Scope ref="emailSubject"/>
<Scope ref="emailBody"/>
<Container name="mail"/>
</Extension>

<!-- GADGET -->

<Extension id="HelloWorldGadget" type="gadget">
  <Name>Hello World Gmail contextual gadget</Name>
  <Url>mydomain/widget-module.xml</Url>
  <Container name="mail"/>
  <!-- Uncomment this to enable Caja. -->
  <!-- <Param name="caja" value="enabled"/> -->
</Extension>

<!-- SCOPE -->

<Scope id="emailSubject">
<Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>


 <Reason>This application searches the Subject: line of each email
  for the text "Hello World."</Reason>
</Scope>

<Scope id="emailBody">
  <Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
  <Reason>This application searches the message body of each email
  for the text "Hello World."</Reason>
</Scope>

</ApplicationManifest>

小部件

    <?xml version="1.0" encoding="UTF-8"?>
<Module>

<ModulePrefs title="Hello World"
    description="Matches and echoes 'Hello World' string in emails"
    height="20"
    author="Sarah M and Walter Q"
    author_email="..."
    author_location="Mountain View, CA">

    <!-- Declare feature dependencies. -->

    <!-- This one is not specific to Gmail contextual gadgets. -->
    <Require feature="dynamic-height"/>

    <!-- The next feature, Caja, is optional, and is supported for
     use only within test domains. Uncomment the tag only for
     non-production gadgets. -->
    <!-- <Require feature="caja"/> -->

    <!-- The next feature, google.contentmatch, is required for all
     Gmail contextual gadgets.
     <Param> - specify one or more comma-separated extractor IDs in
     a param named "extractors". This line is overridden by the extractor ID
     in the manifest, but is still expected to be present. -->
    <Require feature="google.contentmatch">
      <Param name="extractors">
        google.com:HelloWorld
      </Param>
    </Require>

  </ModulePrefs>

  <!-- Define the content type and display location. The settings
   "html" and "card" are required for all Gmail contextual gadgets. -->
  <Content type="html" view="card">
    <![CDATA[
      <!-- Start with Single Sign-On -->
      <script type="text/javascript" src="https://example.com/gadgets/sso.js"></script>
      <script type="text/javascript">

        <!-- Fetch the array of content matches. -->
        matches = google.contentmatch.getContentMatches();
        var matchList = document.createElement('UL');
        var listItem;
        var extractedText;

    //**I JUST WANT THE UNIQUE MESSAGE ID OVER HERE**

        <!-- Iterate through the array and display output for each match. -->
        for (var match in matches) {
          for (var key in matches[match]) {
            listItem = document.createElement('LI');
            extractedText = document.createTextNode(key + ": " + matches[match][key]);
            listItem.appendChild(extractedText);
            matchList.appendChild(listItem);
          }
        }
        document.body.appendChild(matchList);
        gadgets.window.adjustHeight(100);
      </script>
    ]]>
  </Content>
</Module>

如果在这里,我只需要一些独特的信息:

//我只想要这里的唯一消息 ID

编辑 ============================================ ====================================

按照建议,我做了以下更改:

我的清单:

 <?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">

  <!-- Support info to show in the marketplace & control panel -->
  <Support>
    <!-- URL for application setup as an optional redirect during the install -->
    <Link rel="setup" href="https://www.google.com" />
    <!-- URL for application configuration, accessed from the app settings
     page in the control panel -->
    <Link rel="manage" href="https://www.google.com" />
    <!-- URL explaining how customers get support. -->
    <Link rel="support" href="https://www.google.com" />
    <!-- URL that is displayed to admins during the deletion process,
     to specify policies such as data retention, how to claim accounts, etc. -->
    <Link rel="deletion-policy" href="https://www.google.com" />
  </Support>

  <!-- Name and description pulled from message bundles -->
  <Name>HelloWorld</Name>
  <Description>A simple Hello World application for testing
  Gmail contextual gadgets</Description>

  <!-- Show this link in Google's universal navigation for all users -->
  <Extension id="navLink" type="link">
    <Name>HelloWorld</Name>
    <Url>http://www.google.com</Url>
  </Extension>

  <!-- Declare our OpenID realm so our app is white listed -->
  <Extension id="realm" type="openIdRealm">
    <Url>http://_example.com_</Url>
  </Extension>

  <Extension id="uniqueId" type="contextExtractor">
    <Name>Custom_Extractor_7</Name>     
    <Url>sample2ForUniqueReceipients:Custom_Extractor_7</Url>       
    <Triggers ref="HelloWorldGadget" />     
    <Scope ref="senderScope" />     
    <Container name="mail" />       
</Extension> 
<!-- EXTRACTOR 
<Extension id="from" type="contextExtractor">
  <Name>Email Sender</Name>
  <Url>google.com:SenderEmailExtractor</Url>
  <Param name="sender_email" value="amalhotra@ivp.in"/>
  <Triggers ref="HelloWorldGadget"/>
  <Scope ref="senderScope"/>
  <Container name="mail"/>
</Extension>

<Extension id="MessageID" type="contextExtractor">
  <Name>Message ID Extractor</Name>
  <Url>google.com:MessageIDExtractor</Url>
  <Param name="message_id" value=".*"/>
  <Triggers ref="HelloWorldGadget"/>
  <Scope ref="messageID"/>
  <Container name="mail"/>
</Extension>
-->
<!-- GADGET -->

<Extension id="HelloWorldGadget" type="gadget">
  <Name>Hello World Gmail contextual gadget</Name>
  <Url>MY_GADGET_URL</Url>
  <Container name="mail"/>
  <!-- Uncomment this to enable Caja. -->
  <!-- <Param name="caja" value="enabled"/> -->
</Extension>

<!-- SCOPE -->

<Scope id="emailSubject">
  <Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
  <Reason>This application searches the Subject: line of each email
  for the text "Hello World."</Reason>
</Scope>

<Scope id="emailBody">
  <Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
  <Reason>This application searches the message body of each email
  for the text "Hello World."</Reason>
</Scope>

<Scope id="messageID">
  <Url>tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID</Url>
  <Reason>This application searches the message header of each email
  for the text.</Reason>
</Scope>


<Scope id="emailMessageId">
  <Url>tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID</Url>
  <Reason>This would get the message id and most probalbly trigger the widget</Reason>
</Scope>


<Scope id="senderScope">
  <Url>tag:google.com,2010:auth/contextual/extractor/FROM_ADDRESS</Url>
  <Reason>This application searches the Subject: line of each email
    for the text "Hello World."</Reason>
    </Scope>


    </ApplicationManifest>

自定义提取器

 <?xml version="1.0" encoding="UTF-8"?>      
<OpenCOBData id="Custom_Extractor_7">   
    <ExtractorSpec platform="gmail" language="en">
        <Search>        
            <Pattern input_fields="from_email">     
                <![CDATA[(myemailaddress@mydomain.in)]]>       
            </Pattern>      
        </Search>       

        <Response platform="gmail" format="cardgadget">     

            <Output name="id">{@__MESSAGE_ID__}</Output>        
            <Output name="sender">{@__FROM_ADDRESS__}</Output>      
            <Output name="date">{@__DATE_SENT__}</Output>       
            <Output name="to">{@__TO_ADDRESS__}</Output>        

            <!--Output name="email_subject">{@__SUBJECT__}</Output>     
            <Output name="received_date">{@__DATE_RECEIVED__}</Output-->        
        </Response>     
    </ExtractorSpec>        
</OpenCOBData>

【问题讨论】:

    标签: google-apps-script google-api gmail gmail-contextual-gadgets


    【解决方案1】:

    使用消息 id 提取器,它将为您提供前端唯一的消息 id。

    提取器详细信息:

    ID  = google.com:MessageIDExtractor
    
    Description = Matches the Gmail frontend message id of the message (this is a 64-bit hexadecimal value, different from the RFC 822 Message-ID)
    
    Scope   = tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID
    
    Output Fields   = @message_id - Message ID of the message
    

    【讨论】:

    • 你可以在这里找到所有可用的提取器:developers.google.com/gmail/…
    • 现在的问题是,当我为此编写一个提取器时。该小工具将在整个域中触发。所以想要的是我为“发件人”地址编写一个提取器并在我的javascript中获取消息ID。 为什么 因为小部件会为 特定 电子邮件地址加载,并且在我的 javascript 中,我可以将消息 ID 附加到我打算做的任何事情中。我想阻止这个小工具出现在每个人的邮箱中并且仍然想实现我的功能
    【解决方案2】:

    使用这个提取器:

    <?xml version="1.0" encoding="UTF-8"?>      
    <OpenCOBData id="Custom_Extractor_7">   
        <ExtractorSpec platform="gmail" language="en">
            <Search>        
                <Pattern input_fields="from_email">     
                    <![CDATA[(email_1|email_2|email_3)]]>       
                </Pattern>      
            </Search>       
    
            <Response platform="gmail" format="cardgadget">     
    
                <Output name="id">{@__MESSAGE_ID__}</Output>        
                <Output name="sender">{@__FROM_ADDRESS__}</Output>      
                <Output name="date">{@__DATE_SENT__}</Output>       
                <Output name="to">{@__TO_ADDRESS__}</Output>        
    
                <!--Output name="email_subject">{@__SUBJECT__}</Output>     
                <Output name="received_date">{@__DATE_RECEIVED__}</Output-->        
            </Response>     
        </ExtractorSpec>        
    </OpenCOBData>
    

    在下面的行中,将 email_1、email_2、email_3 替换为您想要匹配的电子邮件并添加尽可能多的电子邮件。

    <![CDATA[(email_1|email_2|email_3)]]> 
    

    【讨论】:

    • 好的.... 没试过,但是有一个问题... 我可以在上面的清单中写这个提取器吗?或者这将进入 googleapps 控制台中的 extractor(optional) 部分
    【解决方案3】:

    您必须在 Mamifiest 中添加它的引用,如下所示,

    它还将进入 googleapps 控制台中的提取器(可选)部分。

    像这样在 Manifest 中引用:

    <Extension id="uniqueId" type="contextExtractor">
    
        <Name>Custom_Extractor_7</Name>     
    
        <Url> ProjectID:ExtractorId</Url>       
    
        <Triggers ref="GadgetID" />     
    
        <Scope ref="ScopeId" />     
    
        <Container name="mail" />       
    
    </Extension>     
    

    这里的项目 ID 是您在 Google 应用程序控制台上创建的项目的 ID。

    提取器 ID 是您的自定义提取器的 ID。

    并且 Gadget Id 是您的 Manifest 中存在的小工具部件的 ID。

    Scope Id 是 Manifest 中存在的范围部分的 ID,您可以添加多个范围,这些范围对应于提取器的输出。

    【讨论】:

    • 刚刚试了一下,还是不行。只是为了澄清:(根据您的自定义提取器)我已将清单中的“ExtractorId”替换为“Custom_Extractor_7”....也是我使用过的范围 tag:google.com,2010:auth /contextual/extractor/FROM_ADDRESS 。请告诉我我做错了什么。一切都经过验证,我也重新部署了我的应用程序。
    • 我还需要更改我的小工具文件吗(顺便说一下,它和之前的完全一样——而且它正在工作)。我刚刚上传了自定义提取器(我复制了你的代码)。然后我按照你的解释替换了电子邮件地址。第三,我删除了旧的内容提取器并将其替换为新的(由您提供).. 然后我更改了我的内容提取器标签中的适当值
    • Custom_Extractor_7 不是提取器 ID,它只是一个名称,实际提取器 ID 在扩展标记 &lt;Extension id="uniqueId" type="contextExtractor"&gt; 中指定。这里的 id 属性是提取器的 id。
    猜你喜欢
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多