Skip to content

Commit

Permalink
TF-2602 Set charset for attachment with mimeType=text/plain when se…
Browse files Browse the repository at this point in the history
…nt email on web
  • Loading branch information
dab246 committed Sep 17, 2024
1 parent a0df75f commit c825855
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 49 deletions.
20 changes: 14 additions & 6 deletions contact/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ packages:
dependency: transitive
description:
name: flutter_charset_detector
sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56"
sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.0.0"
flutter_charset_detector_android:
dependency: transitive
description:
Expand All @@ -349,14 +349,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
flutter_charset_detector_ios:
flutter_charset_detector_darwin:
dependency: transitive
description:
name: flutter_charset_detector_ios
sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43
name: flutter_charset_detector_darwin
sha256: daac20390275efb92fbb14350fe11286c5e29c7b80d6b0867f52d760f0d69763
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.1.0"
flutter_charset_detector_platform_interface:
dependency: transitive
description:
Expand All @@ -365,6 +365,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
flutter_charset_detector_web:
dependency: transitive
description:
name: flutter_charset_detector_web
sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b
url: "https://pub.dev"
source: hosted
version: "1.0.2"
flutter_image_compress:
dependency: transitive
description:
Expand Down
13 changes: 6 additions & 7 deletions core/lib/utils/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_charset_detector/flutter_charset_detector.dart';
import 'package:path_provider/path_provider.dart';

class FileUtils {
static const String DEFAULT_CHARSET = 'UTF-8';
static const String DEFAULT_CHARSET = 'uft-8';
static const String TEXT_PLAIN_MIME_TYPE = 'text/plain';

Future<String> _getInternalStorageDirPath({
Expand Down Expand Up @@ -139,14 +139,13 @@ class FileUtils {
}
}

Future<String> getFileCharset(String filePath) async {
Future<String> getCharsetFromBytes(Uint8List bytes) async {
try {
final file = File(filePath);
final decodingResult = await CharsetDetector.autoDecode(file.readAsBytesSync());
logError('FileUtils::getFileCharset: FILE_CHARSET = ${decodingResult.charset}');
return decodingResult.charset;
final decodedResult = await CharsetDetector.autoDecode(bytes);
log('FileUtils::getCharsetFromBytes: FILE_CHARSET = ${decodedResult.charset}');
return decodedResult.charset;
} catch (e) {
logError('FileUtils::getFileCharset: Exception: $e');
logError('FileUtils::getCharsetFromBytes: Exception: $e');
return DEFAULT_CHARSET;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/utils/web_renderer/canvas_kit_web.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:js' as js;
import 'package:universal_html/js.dart' as js;

/// Whether the CanvasKit renderer is being used on web.
///
Expand Down
20 changes: 14 additions & 6 deletions core/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ packages:
dependency: "direct main"
description:
name: flutter_charset_detector
sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56"
sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.0.0"
flutter_charset_detector_android:
dependency: transitive
description:
Expand All @@ -342,14 +342,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_charset_detector_ios:
flutter_charset_detector_darwin:
dependency: transitive
description:
name: flutter_charset_detector_ios
sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43
name: flutter_charset_detector_darwin
sha256: d17c1847366a0501449d95d18a43417585841afe10200ceefb4422e6b7fccefb
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.0.0"
flutter_charset_detector_platform_interface:
dependency: transitive
description:
Expand All @@ -358,6 +358,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
flutter_charset_detector_web:
dependency: transitive
description:
name: flutter_charset_detector_web
sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b
url: "https://pub.dev"
source: hosted
version: "1.0.2"
flutter_image_compress:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dependencies:

fk_user_agent: 2.1.0

flutter_charset_detector: 2.0.0
flutter_charset_detector: 3.0.0

dev_dependencies:
flutter_test:
Expand Down
11 changes: 6 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ PODS:
- flutter_appauth (0.0.1):
- AppAuth (= 1.7.4)
- Flutter
- flutter_charset_detector_ios (0.0.1):
- flutter_charset_detector_darwin (0.0.1):
- Flutter
- FlutterMacOS
- UniversalDetector2 (= 2.0.1)
- flutter_downloader (0.0.1):
- Flutter
Expand Down Expand Up @@ -205,7 +206,7 @@ DEPENDENCIES:
- fk_user_agent (from `.symlinks/plugins/fk_user_agent/ios`)
- Flutter (from `Flutter`)
- flutter_appauth (from `.symlinks/plugins/flutter_appauth/ios`)
- flutter_charset_detector_ios (from `.symlinks/plugins/flutter_charset_detector_ios/ios`)
- flutter_charset_detector_darwin (from `.symlinks/plugins/flutter_charset_detector_darwin/darwin`)
- flutter_downloader (from `.symlinks/plugins/flutter_downloader/ios`)
- flutter_image_compress_common (from `.symlinks/plugins/flutter_image_compress_common/ios`)
- flutter_inappwebview_ios (from `.symlinks/plugins/flutter_inappwebview_ios/ios`)
Expand Down Expand Up @@ -273,8 +274,8 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_appauth:
:path: ".symlinks/plugins/flutter_appauth/ios"
flutter_charset_detector_ios:
:path: ".symlinks/plugins/flutter_charset_detector_ios/ios"
flutter_charset_detector_darwin:
:path: ".symlinks/plugins/flutter_charset_detector_darwin/darwin"
flutter_downloader:
:path: ".symlinks/plugins/flutter_downloader/ios"
flutter_image_compress_common:
Expand Down Expand Up @@ -333,7 +334,7 @@ SPEC CHECKSUMS:
fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_appauth: 1ce438877bc111c5d8f42da47729909290624886
flutter_charset_detector_ios: 5157d0104855b9deb78e1395515a287197bc2d55
flutter_charset_detector_darwin: fb3692d6d72cb6afcce7b0dd1a9516be6e78556e
flutter_downloader: b7301ae057deadd4b1650dc7c05375f10ff12c39
flutter_image_compress_common: ec1d45c362c9d30a3f6a0426c297f47c52007e3e
flutter_inappwebview_ios: 97215cf7d4677db55df76782dbd2930c5e1c1ea0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:core/data/network/dio_client.dart';
import 'package:core/data/network/download/download_client.dart';
import 'package:core/utils/application_manager.dart';
import 'package:core/utils/file_utils.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/http/http_client.dart';
import 'package:tmail_ui_user/features/base/base_bindings.dart';
Expand Down Expand Up @@ -38,7 +39,10 @@ class PublicAssetBindings extends BaseBindings {
@override
void dependencies() {
Get.lazyPut(
() => FileUploader(Get.find<DioClient>(tag: BindingTag.isolateTag), Get.find<Executor>()),
() => FileUploader(
Get.find<DioClient>(tag: BindingTag.isolateTag),
Get.find<Executor>(),
Get.find<FileUtils>()),
tag: BindingTag.publicAssetBindingsTag);
Get.lazyPut(
() => PublicAssetApi(Get.find<HttpClient>(), Get.find<Uuid>()),
Expand Down
22 changes: 17 additions & 5 deletions lib/features/upload/data/network/file_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ class FileUploader {
);
log('FileUploader::_handleUploadAttachmentAction(): RESULT_JSON = $resultJson');
if (argsUpload.mobileFileUpload.mimeType == FileUtils.TEXT_PLAIN_MIME_TYPE) {
final fileCharset = await argsUpload.fileUtils.getFileCharset(argsUpload.mobileFileUpload.filePath);
final fileCharset = await argsUpload.fileUtils.getCharsetFromBytes(
File(argsUpload.mobileFileUpload.filePath).readAsBytesSync()
);
return _parsingResponse(
resultJson: resultJson,
fileName: argsUpload.mobileFileUpload.fileName,
fileCharset: fileCharset);
fileCharset: fileCharset.toLowerCase());
} else {
return _parsingResponse(
resultJson: resultJson,
Expand All @@ -140,7 +142,7 @@ class FileUploader {
requestOptions: exception.requestOptions.copyWith(data: ''));
} catch (exception) {
logError('FileUploader::_handleUploadAttachmentAction():OtherException: $exception');

rethrow;
}
}
Expand Down Expand Up @@ -181,8 +183,18 @@ class FileUploader {
);
}
);
log('FileUploader::_handleUploadAttachmentActionOnWeb():resultJson: $resultJson');
return _parsingResponse(resultJson: resultJson, fileName: fileInfo.fileName);
log('FileUploader::_handleUploadAttachmentActionOnWeb(): RESULT_JSON = $resultJson');
if (fileInfo.mimeType == FileUtils.TEXT_PLAIN_MIME_TYPE) {
final fileCharset = await _fileUtils.getCharsetFromBytes(fileInfo.bytes!);
return _parsingResponse(
resultJson: resultJson,
fileName: fileInfo.fileName,
fileCharset: fileCharset.toLowerCase());
} else {
return _parsingResponse(
resultJson: resultJson,
fileName: fileInfo.fileName);
}
}

static Attachment _parsingResponse({
Expand Down
20 changes: 14 additions & 6 deletions model/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ packages:
dependency: transitive
description:
name: flutter_charset_detector
sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56"
sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.0.0"
flutter_charset_detector_android:
dependency: transitive
description:
Expand All @@ -349,14 +349,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
flutter_charset_detector_ios:
flutter_charset_detector_darwin:
dependency: transitive
description:
name: flutter_charset_detector_ios
sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43
name: flutter_charset_detector_darwin
sha256: daac20390275efb92fbb14350fe11286c5e29c7b80d6b0867f52d760f0d69763
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.1.0"
flutter_charset_detector_platform_interface:
dependency: transitive
description:
Expand All @@ -365,6 +365,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
flutter_charset_detector_web:
dependency: transitive
description:
name: flutter_charset_detector_web
sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b
url: "https://pub.dev"
source: hosted
version: "1.0.2"
flutter_image_compress:
dependency: transitive
description:
Expand Down
20 changes: 14 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ packages:
dependency: transitive
description:
name: flutter_charset_detector
sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56"
sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.0.0"
flutter_charset_detector_android:
dependency: transitive
description:
Expand All @@ -671,14 +671,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_charset_detector_ios:
flutter_charset_detector_darwin:
dependency: transitive
description:
name: flutter_charset_detector_ios
sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43
name: flutter_charset_detector_darwin
sha256: d17c1847366a0501449d95d18a43417585841afe10200ceefb4422e6b7fccefb
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.0.0"
flutter_charset_detector_platform_interface:
dependency: transitive
description:
Expand All @@ -687,6 +687,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
flutter_charset_detector_web:
dependency: transitive
description:
name: flutter_charset_detector_web
sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b
url: "https://pub.dev"
source: hosted
version: "1.0.2"
flutter_colorpicker:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit c825855

Please sign in to comment.