在gmail上下文小工具中获取邮件id/唯一id



我正在尝试编写一个GMAIL上下文小工具。我已经准备好了所有的构建块(服务、小工具、清单、存储库……)基本的hello世界工作正常。

为了简化,我们说,在我的小部件

中,"我有一个标记为收藏的"功能

我将需要存储(在我的SQL数据库中)一些对象对一些标记为最喜欢的邮件。

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

ques:在我的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在这里

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

根据建议,我做了以下修改:

My Manifest:

 <?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>

使用消息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

使用此提取器:

<?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)]]> 

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

并且它也将进入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>     

这里的Project Id是你在Google apps控制台创建的项目的Id。

Extractor Id是自定义提取器的Id。

Gadget Id是Manifest中显示的Gadget部件的Id。

作用域Id是你的作用域部分的Id,你可以添加多个作用域,这些对应于你的提取器的输出。

相关内容

  • 没有找到相关文章

最新更新