Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 74921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:26:03+00:00 2026-05-10T20:26:03+00:00

I have many emails coming in from different sources. they all have attachments, many

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:26:03+00:00Added an answer on May 10, 2026 at 8:26 pm

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many applications across an enterprise environment and they all use different methods
I am learning RoR coming from many years of c# and MSSQL. I have
I have many dependency properties in my WPF usercontrol and many of them are
I have many (about 1000) images (printscreens), and I need to crop these images
So, this question has been asked lots, and i have seen many different answers,
I have an application that reads emails from ONE email account (gmail application account)
I have a table that tracks emails sent from applications on my server. I
I have many tables that use Lookup/Enum references for most of their column values.
I have MANY small Test Projects where I put together just enough code to
I have many links in my page. For example <a href=/promotions/download/schools/australia.aspx>Australia</a> Now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.