我正在尝试编写一个 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>