LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   decode a non latin character string utf8 (https://www.linuxquestions.org/questions/linux-newbie-8/decode-a-non-latin-character-string-utf8-918247/)

ted_chou12 12-11-2011 08:08 PM

decode a non latin character string utf8
 
Hi, I am not sure how to say this, but when I fetch emails, and the attachment filenames are in chinese, the filenames are not correctly displayed:
Code:

=?Big5?B?pmu3Uafvs3mkSKfvwsMgT1ZBKDEtNrawp7kpLnRvcnJlbnQ=?=
So the file extension and the proper name is lost. But when I try to send this file back to gmail, hotmail..etc, the filename in attachment does display correctly in chinese. I think that suggest this string could be decoded with some sort of function. iconv? I am sorry, but could anyone guide me in the right direction?
Thanks,
Ted

Randicus Draco Albus 12-11-2011 08:28 PM

In addition to utf8, you may need to add big5. I have both installed on my Debian system (which you are apparently using) and I have no problems with displaying Chinese characters.
Is it safe to assume you have either IBus or SCIM installed? If so, just added extra Chinese input methods.
I do not know if it is necessary to add Chinese to the locales, but if you have not already done so, it would not hurt.
I hope that helps.

ted_chou12 12-12-2011 09:26 AM

Hi, thanks for the information, but I am not sure if it is actually the input, the here is the top part of the email file:
Code:

From .com  Fri Nov 25 08:24:05 2011
Return-Path: <@gmail.com>
Received: from nas (localhost [127.0.0.1])
        by nas (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pAPFNwjF007969
        for <root@localhost>; Fri, 25 Nov 2011 08:23:59 -0700
Delivered-To:
Received: from gmail-pop.l.google.com [74.125.53.109]
        by nas with POP3 (fetchmail-6.3.9-rc2)
        for <root@localhost> (single-drop); Fri, 25 Nov 2011 08:23:59 -0700 (MST)
Received: by 10.216.123.12 with SMTP id u12cs217593weh;
        Fri, 25 Nov 2011 07:14:59 -0800 (PST)
Received: by 10.100.237.19 with SMTP id k19mr7429387anh.163.1322234096872;
        Fri, 25 Nov 2011 07:14:56 -0800 (PST)
Received: from mail-qw0-f50.google.com (mail-qw0-f50.google.com [209.85.216.50])
        by mx.google.com with ESMTPS id w20si9054227and.192.2011.11.25.07.14.56
        (version=TLSv1/SSLv3 cipher=OTHER);
        Fri, 25 Nov 2011 07:14:56 -0800 (PST)
Received-SPF: pass (google.com: domain of designates 209.85.216.50 as permitted sender) client-ip=209.85.216.50;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of @gmail.com designates 209.85.216.50 as permitted sender) smtp.mail=@gmail.com; dkim=pass (test mode) header.i=@gmail.com
Received: by qadb12 with SMTP id b12so3401151qad.9
        for <>; Fri, 25 Nov 2011 07:14:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=mime-version:date:message-id:subject:from:to:content-type;
        bh=d95Vwe9KGaQe4rC3Qhr/8HGjNu+W/peleuKyjiIGYe4=;
        b=WXYViW1/GCZXqlevDB6Ji175FDGzStJIObQpuprhANjqBYANh3q11mBfOnjtXJoKSu
        ntHaOlOMCgSDb/Hwn4/pSz5RobLOTZiZCNZj8N1eGuZMAx81rUrbiVSp9aIjw1sWdsZY
        dkaOKE4Z+NPw7/Xb0lye0ib8Y5qtdNPcjEP3E=
MIME-Version: 1.0
Received: by 10.182.188.34 with SMTP id fx2mr10381628obc.31.1322234095924;
 Fri, 25 Nov 2011 07:14:55 -0800 (PST)
Received: by 10.182.122.9 with HTTP; Fri, 25 Nov 2011 07:14:55 -0800 (PST)
Date: Fri, 25 Nov 2011 08:14:55 -0700
Message-ID: <CAG4-7shs5rP1puNq0z4WqYsy05Jw2PTR+hNq616AJcKxgBrhMQ@mail.gmail.com>
Subject:
From: <@gmail.com>
To:
Content-Type: multipart/mixed; boundary=f46d04446a6798f7a904b2909dff

--f46d04446a6798f7a904b2909dff
Content-Type: multipart/alternative; boundary=f46d04446a6798f7a504b2909dfd

--f46d04446a6798f7a504b2909dfd
Content-Type: text/plain; charset=ISO-8859-1



--f46d04446a6798f7a504b2909dfd
Content-Type: text/html; charset=ISO-8859-1

<br>

--f46d04446a6798f7a504b2909dfd--
--f46d04446a6798f7a904b2909dff
Content-Type: application/octet-stream;
        name="=?Big5?B?pmu3Uafvs3mkSKfvwsMgT1ZBKDEtNrawp7kpLnRvcnJlbnQ=?="
Content-Disposition: attachment;
        filename="=?Big5?B?pmu3Uafvs3mkSKfvwsMgT1ZBKDEtNrawp7kpLnRvcnJlbnQ=?="
Content-Transfer-Encoding: base64
X-Attachment-Id: f_gvfc0wzs0

ZDg6YW5ub3VuY2UzNzpodHRwOi8vdHJhY2tlci5rdHhwLmNvbTo2ODY4L2Fubm91bmNlMTM6YW5u
b3VuY2UtbGlzdGxsMzc6aHR0cDovL3RyYWNrZXIua3R4cC5jb206Njg2OC9hbm5vdW5jZWVsMzc6
aHR0cDovL3RyYWNrZXIua3R4cC5jb206NzA3MC9hbm5vdW5jZWVsNDU6aHR0cDovL3RyYWNrZXIu

The line is "=?Big5?B?pmu3Uafvs3mkSKfvwsMgT1ZBKDEtNrawp7kpLnRvcnJlbnQ=?=". I wonder what encode format is this? I tried base64, its not.
Thanks,
Ted

ted_chou12 12-12-2011 02:54 PM

Thanks to this:http://cgi.blog.roodo.com/comment#commentForm
This php script:
Code:

$sub="中文字碼";
$sub="=?UTF-8?B?". base64_encode($sub)."?=";

I wonder if there are packages specialized in decoding strings of base64 in bash? can anyone suggest me?
Thanks,
Ted
GOT IT:
Code:


echo "pECkSKVopdVspPQudHh0" | perl -MMIME::Base64 -ne 'print decode_base64($_)'

might also find this useful:
http://codebase.tuxnet24.de/index.ph...19&snippets=23
Thanks,


All times are GMT -5. The time now is 09:47 AM.