• <tfoot id='IixDi'></tfoot>
      <bdo id='IixDi'></bdo><ul id='IixDi'></ul>
    <legend id='IixDi'><style id='IixDi'><dir id='IixDi'><q id='IixDi'></q></dir></style></legend>
    <i id='IixDi'><tr id='IixDi'><dt id='IixDi'><q id='IixDi'><span id='IixDi'><b id='IixDi'><form id='IixDi'><ins id='IixDi'></ins><ul id='IixDi'></ul><sub id='IixDi'></sub></form><legend id='IixDi'></legend><bdo id='IixDi'><pre id='IixDi'><center id='IixDi'></center></pre></bdo></b><th id='IixDi'></th></span></q></dt></tr></i><div id='IixDi'><tfoot id='IixDi'></tfoot><dl id='IixDi'><fieldset id='IixDi'></fieldset></dl></div>

        <small id='IixDi'></small><noframes id='IixDi'>

      1. 如何判断字符串是否为base64

        how to tell if a string is base64 or not(如何判断字符串是否为base64)
          <legend id='FKJjN'><style id='FKJjN'><dir id='FKJjN'><q id='FKJjN'></q></dir></style></legend>

              <tbody id='FKJjN'></tbody>

              • <i id='FKJjN'><tr id='FKJjN'><dt id='FKJjN'><q id='FKJjN'><span id='FKJjN'><b id='FKJjN'><form id='FKJjN'><ins id='FKJjN'></ins><ul id='FKJjN'></ul><sub id='FKJjN'></sub></form><legend id='FKJjN'></legend><bdo id='FKJjN'><pre id='FKJjN'><center id='FKJjN'></center></pre></bdo></b><th id='FKJjN'></th></span></q></dt></tr></i><div id='FKJjN'><tfoot id='FKJjN'></tfoot><dl id='FKJjN'><fieldset id='FKJjN'></fieldset></dl></div>
                  <bdo id='FKJjN'></bdo><ul id='FKJjN'></ul>

                  <small id='FKJjN'></small><noframes id='FKJjN'>

                  <tfoot id='FKJjN'></tfoot>
                • 本文介绍了如何判断字符串是否为base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have many emails coming in from different sources. they all have attachments, many of them have attachment names in chinese, so these names are converted to base64 by their email clients.

                  When I receive these emails, I wish to decode the name. but there are other names which are not base64. How can I differentiate whether a string is base64 or not, using the jython programming language?

                  Ie.

                  First attachment:

                  ------=_NextPart_000_0091_01C940CC.EF5AC860
                  Content-Type: application/vnd.ms-excel;
                   name="Copy of Book1.xls"
                  Content-Transfer-Encoding: base64
                  Content-Disposition: attachment;
                   filename="Copy of Book1.xls"
                  

                  second attachment:

                  ------=_NextPart_000_0091_01C940CC.EF5AC860
                  Content-Type: application/vnd.ms-excel;
                   name="=?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?="
                  Content-Transfer-Encoding: base64
                  Content-Disposition: attachment;
                   filename="=?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?="  
                  

                  Please note both "Content-Transfer-Encoding" have base64

                  解决方案

                  Please note both Content-Transfer-Encoding have base64

                  Not relevant in this case, the Content-Transfer-Encoding only applies to the body payload, not to the headers.

                  =?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?=
                  

                  That's an RFC2047-encoded header atom. The stdlib function to decode it is email.header.decode_header. It still needs a little post-processing to interpret the outcome of that function though:

                  import email.header
                  x= '=?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?='
                  try:
                      name= u''.join([
                          unicode(b, e or 'ascii') for b, e in email.header.decode_header(x)
                      ])
                  except email.Errors.HeaderParseError:
                      pass # leave name as it was
                  

                  However...

                  Content-Type: application/vnd.ms-excel;
                   name="=?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?="
                  

                  This is simply wrong. What mailer created it? RFC2047 encoding can only happen in atoms, and a quoted-string is not an atom. RFC2047 §5 explicitly denies this:

                  • An 'encoded-word' MUST NOT appear within a 'quoted-string'.

                  The accepted way to encode parameter headers when long string or Unicode characters are present is RFC2231, which is a whole new bag of hurt. But you should be using a standard mail-parsing library which will cope with that for you.

                  So, you could detect the '=?' in filename parameters if you want, and try to decode it via RFC2047. However, the strictly-speaking-correct thing to do is to take the mailer at its word and really call the file =?gb2312?B?uLGxvmhlbrixsb5nLnhscw==?=!

                  这篇关于如何判断字符串是否为base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                    <tbody id='zuCU7'></tbody>
                    <i id='zuCU7'><tr id='zuCU7'><dt id='zuCU7'><q id='zuCU7'><span id='zuCU7'><b id='zuCU7'><form id='zuCU7'><ins id='zuCU7'></ins><ul id='zuCU7'></ul><sub id='zuCU7'></sub></form><legend id='zuCU7'></legend><bdo id='zuCU7'><pre id='zuCU7'><center id='zuCU7'></center></pre></bdo></b><th id='zuCU7'></th></span></q></dt></tr></i><div id='zuCU7'><tfoot id='zuCU7'></tfoot><dl id='zuCU7'><fieldset id='zuCU7'></fieldset></dl></div>
                    <legend id='zuCU7'><style id='zuCU7'><dir id='zuCU7'><q id='zuCU7'></q></dir></style></legend>

                    <tfoot id='zuCU7'></tfoot>

                      • <bdo id='zuCU7'></bdo><ul id='zuCU7'></ul>
                          • <small id='zuCU7'></small><noframes id='zuCU7'>