电子邮件主题中的动画图标 [英] Animated icon in email subject

查看:18
本文介绍了电子邮件主题中的动画图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 列表中的图标,还有其他几个遵循相同的约定.

请注意,还有一些图标的名称带有前缀,例如 ,尽管它确实有一些相似之处.它实际上是一种在电子邮件主题中编码非 ASCII 字符的特殊语法,在 RFC 2047.基本上,它是这样工作的.

=?charset?encoding?data?=

所以,在我们的示例字符串中,我们有以下数据.

=?UTF-8?B?876Urg==?=

  • charset = UTF-8
  • encoding = B(表示base64)
  • 数据 = 876Urg==

#那么它是怎样工作的?

我们知道,不知何故,876Urg== 表示图标 52E,但如何?

如果我们对 876Urg== 进行 base64 解码,我们会得到 0xf3be94ae.这在二进制中如下所示:

11110011 10111110 10010100 10101110

这些位与 4 字节 UTF-8 编码字符一致.

11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

所以相关位如下:

 011 111110 010100 101110

或者当对齐时:

00001111 11100101 00101110

在十六进制中,这些字节如下:

FE52E

如您所见,除了 FE 前缀可能是为了将 goomoji 图标与其他 UTF-8 字符区分开来,它与 52E 在图标 URL 中.一些测试证明这适用于其他图标.


#听起来工作量很大,有转换器吗?:

这当然可以编写脚本.我为我的测试创建了以下 Python 代码.这些函数可以将 base64 编码的字符串与 URL 中的短十六进制字符串进行转换.请注意,此代码是为 Python 3 编写的,与 Python 2 不兼容.

###转换函数:

导入base64def goomoji_decode(代码):#Base64 解码.二进制 = base64.b64decode(代码)#UTF-8 解码.解码 = binary.decode('utf8')#获取UTF-8值.值 = ord(解码)#Hex 编码,修剪 'FE' 前缀和大写.返回格式(值,'x')[2:].upper()def goomoji_encode(代码):#添加'FE'前缀并解码.值 = int('FE' + 代码,16)#转换为UTF-8字符.编码 = chr(值)#将 UTF-8 编码为二进制.二进制=字节数组(编码,'utf8')#Base64 编码 return end 返回一个 UTF-8 字符串.返回 base64.b64encode(binary).decode('utf-8')

###示例:

print(goomoji_decode('876Urg=='))打印(goomoji_encode('52E'))

###输出:

52E876Urg==

当然,查找图标的 URL 只需要在 Gmail 中创建一个新草稿,插入所需的图标,并使用浏览器的 DOM 检查器.

I know about Data URIs in which base64 encoded data can be used inline such as images. Today I received an email actually an spam one in which there was an animated (gif) icon in its subject:

Here is the icon alone:

So the only thing did cross my mind was all about Data URIs and if Gmail allows some sort of emoticons to be inserted in subject. I saw the full detailed version of email and pointed to subject line at the below picture:

So GIF comes from =?UTF-8?B?876Urg==?= encoded string which is similar to Data URI scheme however I couldn't get the icon out of it. Here is element HTML source:

Long story short, there are lots of emoticons from https://mail.google.com/mail/e/XXX where XXX are hexadecimal numbers. They are documented nowhere or I couldn't find it. If that's about Data URI, so how is it possible to include them in Gmail's email subject? (I forwarded that email to a yahoo email account, seeing [?] instead of icon) and if it's not, then how that encoded string is parsed?

解决方案

#Short description:

They are referred to internally as goomoji, and they appear to be a non-standard UTF-8 extension. When Gmail encounters one of these characters, it is replaced by the corresponding icon. I wasn't able to find any documentation on them, but I was able to reverse engineer the format.


#What are these icons?

Those icons are actually the icons that appear under the "Insert emoticons" panel.

While I don't see the 52E icon in the list, there are several others that follow the same convention.

Note that there are also some icons whose names are prefixed, such as gtalk.03C . I was not able to determine if or how these icons can be used in this manner.


#What is this Data URI thing?

It's not actually a Data URI, though it does share some similarities. It's actually a special syntax for encoding non-ASCII characters in email subjects, defined in RFC 2047. Basically, it works like this.

=?charset?encoding?data?=

So, in our example string, we have the following data.

=?UTF-8?B?876Urg==?=

  • charset = UTF-8
  • encoding = B (means base64)
  • data = 876Urg==

#So, how does it work?

We know that somehow, 876Urg== means the icon 52E, but how?

If we base64 decode 876Urg==, we get 0xf3be94ae. This looks like the following in binary:

11110011 10111110 10010100 10101110

These bits are consistent with a 4-byte UTF-8 encoded character.

11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

So the relevant bits are the following.:

     011   111110   010100   101110

Or when aligned:

00001111 11100101 00101110

In hexadecimal, these bytes are the following:

FE52E

As you can see, except for the FE prefix which is presumably to distinguished the goomoji icons from other UTF-8 characters, it matches the 52E in the icon URL. Some testing proves that this holds true for other icons.


#Sounds like a lot of work, is there a converter?:

This can of course be scripted. I created the following Python code for my testing. These functions can convert the base64 encoded string to and from the short hex string found in the URL. Note, this code is written for Python 3, and is not Python 2 compatible.

###Conversion functions:

import base64

def goomoji_decode(code):
    #Base64 decode.
    binary = base64.b64decode(code)
    #UTF-8 decode.
    decoded = binary.decode('utf8')
    #Get the UTF-8 value.
    value = ord(decoded)
    #Hex encode, trim the 'FE' prefix, and uppercase.
    return format(value, 'x')[2:].upper()

def goomoji_encode(code):
    #Add the 'FE' prefix and decode.
    value = int('FE' + code, 16)
    #Convert to UTF-8 character.
    encoded = chr(value)
    #Encode UTF-8 to binary.
    binary = bytearray(encoded, 'utf8')
    #Base64 encode return end return a UTF-8 string. 
    return base64.b64encode(binary).decode('utf-8')

###Examples:

print(goomoji_decode('876Urg=='))
print(goomoji_encode('52E'))

###Output:

52E
876Urg==

And, of course, finding an icon's URL simply requires creating a new draft in Gmail, inserting the icon you want, and using your browser's DOM inspector.

这篇关于电子邮件主题中的动画图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆