diff --git a/app/package.json b/app/package.json index b52543046..f7dd4cbd0 100644 --- a/app/package.json +++ b/app/package.json @@ -74,6 +74,7 @@ "tld": "^0.0.2", "underscore": "1.8.x", "underscore.string": "^3.0", + "utf7": "^1.0.2", "windows-shortcuts": "emorikawa/windows-shortcuts#b0a0fc7" }, "optionalDependencies": { diff --git a/app/spec/models/category-spec.coffee b/app/spec/models/category-spec.coffee index dedbac3d8..10df113de 100644 --- a/app/spec/models/category-spec.coffee +++ b/app/spec/models/category-spec.coffee @@ -25,6 +25,10 @@ describe 'Category classes', -> foo = new Folder({path: 'INBOX'}) expect(foo.displayName).toEqual('Inbox') + it "should convert the UTF7-formatted path back to UTF8", -> + foo = new Label({path: 'T&AOk-st F&APg-reign L&AOU-bel'}) + expect(foo.displayName).toEqual('Tést Føreign Låbel') + describe 'category types', -> it 'assigns type correctly when it is a user category', -> cat = new Label diff --git a/app/src/flux/models/category.es6 b/app/src/flux/models/category.es6 index 5d321d9a9..276fdb704 100644 --- a/app/src/flux/models/category.es6 +++ b/app/src/flux/models/category.es6 @@ -1,4 +1,5 @@ /* eslint global-require: 0 */ +import utf7 from 'utf7'; import Model from './model'; import Attributes from '../attributes'; @@ -57,15 +58,17 @@ Section: Models */ export default class Category extends Model { get displayName() { + const decoded = utf7.imap.decode(this.path); + for (const prefix of ['INBOX', '[Gmail]', '[Mailspring]']) { - if (this.path.startsWith(prefix) && this.path.length > prefix.length + 1) { - return this.path.substr(prefix.length + 1); // + delimiter + if (decoded.startsWith(prefix) && decoded.length > prefix.length + 1) { + return decoded.substr(prefix.length + 1); // + delimiter } } - if (this.path === 'INBOX') { + if (decoded === 'INBOX') { return 'Inbox'; } - return this.path; + return decoded; } /* Available for historical reasons, do not use. */