Code Monkey home page Code Monkey logo

Comments (21)

tomholub avatar tomholub commented on July 24, 2024

Note for myself. I will probably do this inside MimeMessage.

var thread_message_id_last = tool.api.gmail.find_header(thread.messages[thread.messages.length - 1], 'Message-ID') || '';
var thread_message_referrences_last = tool.api.gmail.find_header(thread.messages[thread.messages.length - 1], 'In-Reply-To') || '';
compose.headers({ 'In-Reply-To': thread_message_id_last, 'References': thread_message_referrences_last + ' ' + thread_message_id_last });

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

For now, you can create the screen for reply and just make sure to send it back to the original sender and use the same title.

newTitle = "Re: " + oldTitle

Meanwhile I'll work on the headers.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

e577456

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

you can now pass the previous MimeMessage to a new reply like this:

public String mime_encode(String body, PgpContact[] to, PgpContact from, String subject, Attachment[] attachments, MimeMessage reply_to);

or pass a null for new messages.

It will automatically add reply headers.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

Today I tried to implement the addition of headers using the code

public String mime_encode(String body, PgpContact[] to, PgpContact from, String subject, Attachment[] attachments, MimeMessage reply_to);

But I failed. The problem lies in the class Js. I can not use it to transfer data between the elements of the application. I will investigate the class Js in detail and suggest a solution to this problem. At the moment, I can say for sure that this class needs to be designed as a utility class. Then it will work fine in the life cycle of the application.

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

Yes, as far as I understand it, data cannot really be transferred in between instances of Js if the data is represented as a JavaScript object (which it sometimes has to be).

Is it possible to use a single Js class in a background thread and access is from other threads through some queue mechanism?

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

Alternatively, we could try to work around it by representing the data in Java and converting it back to JavaScript where necessary.

The first solution would be an all-fixing solution but may be a bit complicated.

The second solution is a simpler design, but we may bump into limitations down the road.

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

A quick fix for this specific case would be to create a MimeMessage from the original string again, using the same Js object that it will be used in.

Something like this:

js.mime_encode("text", to, from, "subject", null, js.mime_decode(original_mime_stream));

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

Today I explored how the J2V8 library works. Now I already have some idea of what and how it works.

Is it possible to use a single Js class in a background thread and access is from other threads through some queue mechanism?

Yes, it is possible. But this solution not simple. Then I need to think about the logic of interaction between threads. In this case, there can be a lot of nuances. I think it's better to postpone this question for now.

For the time being, I realized that the Js object can only be used in the current thread. Accordingly, for each thread need to create the own object. Otherwise, nothing will work and I will get an error "Caused by: java.lang.Error: Invalid V8 thread access". Threading Model/JavaScript itself is single threaded and J2V8 enforces this. All access to a single runtime must be from the same thread. This ensures that there are no race conditions (or deadlock potential) when manipulating or working with a single JavaScript runtime.

I think it's

The second solution is a simpler design, but we may bump into limitations down the road.

better for now.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

For me: eclipsesource/J2V8#33

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

Here's what we ended up doing in Swift for the time being:

                     let mime = js.mime_encode(
                         body: encrypted,
                         to: [PgpContact(email: self.txtRecipient.text!, name: nil)],
                         from: PgpContact(email: email, name: name),
                         subject: "Re: " + self.objMessage.header.subject,
                         attachments: [],
                         replyTo: js.mime_decode(mime_message: self.replyToMime)
                      )
                      self.sendMail(message: mime)

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

Today I again returned to this issue. And I wanted to clarify some points. When I receive a message in RAW format, I download the whole message. Accordingly, if the message has attachments, then they are also downloaded. And this is bad since the user has to wait until the big message downloads. In order to solve the problem of correctly sending a reply, I have the following options:

  1. I can download a message in RAW format, but I'll only download headers. Then I can use the Js class to form a reply (I hope so. I have not tested it yet). Then the message will not be large and I can easily transfer it between the screens.
  2. I will use the Js class only to encrypt the message, and I will be to create a reply via the JavaMail library.

If need, I can attach examples of the full RAW message and the RAW message with headers only.

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

I think the headers only should work, as long as they are still in the MIME format.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

Yes it will be the MIME format. Ok, I'll try this option.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

I was wrong. Here, not everything is so simple.

At the moment, in order to use the Js class for parsing a message, I need to send him a message in the raw format.
But by standard using of JavaMail, from the IMAP server I receive the whole message, including attachments. (For example, the command "A0 UID FETCH 22049"). In this case, the user will wait a long time, if there are large attachments.

This all gave me no peace. Then I tried to receive via JavaMail only the structure of the message (A5 FETCH 17 (BODYSTRUCTURE)), form a new request to the IMAP server, where no attachments will be included.

Example query:

A6 UID FETCH 1603 (BODY[HEADER] BODY[1] BODY[2])

Example response:

Delivered-To: [email protected]
Received: by 10.107.28.213 with SMTP id c204csp405325ioc; Sat, 10 Jun 2017
 13:44:07 -0700 (PDT)
X-Received: by 10.13.214.87 with SMTP id y84mr19393719ywd.303.1497127447757;
 Sat, 10 Jun 2017 13:44:07 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1497127447; cv=none; d=google.com;
 s=arc-20160816;
 b=BPwkOuToc2whu5rlcHk3w43f4zwCKJsYiVIBTMSw3n6aVgE4OqCiWTnOwYGEGESY/V
 vekOunJ+VJhAbYlbM48buQvn+T5N6O59tdSIubh8DDNbKtK3vcTqNvhqCsAw8ziG2/W6
 kXgmyj9cn72j8kVeHRkTbwNdm6Z4pcG2Ka4d8CVytDKHwqrCcRUFW5TYc6RVtOgCK2vh
 onGAU/Xz3h/aLx9h/g0jN9ptRPDXfSSjTPXgQZ1375BwisYppTLGVlWuM1vOZFfvNmxS
 MgANB7Hzs7C/t+lSTDZqEy64X/pv5U2F/PEGAA+l+AIdM3zKs9UDglTBS1ACyIS3z4C3 /r9w==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
 s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature
 :arc-authentication-results; bh=hTqw4/u5vB/cYxt7m8lnobdoP2XufhBU7f2IuwIJU4c=;
 b=WAR4Ejaygwq5CtstxlI7s3wCTP/Clfe4T/NJCF3ivdVA3EQOfS4yRWBNaRhxB46bm9
 +R3515WZexyDSSG3FKY99MEly4P3bQ5wDVCwtzfxTYwsfk2VXJ95i/YDNYKhIWglRng1
 AfAVnWmHxZtw5uIRuYc1gaSYgJRscmeuQ+RIYJzrnKlsYPytx/RINlZUFwceuRX/uOVa
 BgarvtvzBNpuKtZbKOzR2eGv9UvsReLN5+3xfg3Sm9fralGsc1rQVjw1FtY3vSK/Si+2
 IqGUxh46MJxCuvwFBGSu5tGW/XU9/MZL2HDk2okHq0rJx6FRY3Pl3/s2qyHu3p/Vl86o Tdcw==
ARC-Authentication-Results: i=1; mx.google.com; dkim=pass [email protected];
 spf=pass (google.com: domain of [email protected] designates
 2607:f8b0:4002:c05::22b as permitted sender)
 [email protected]; dmarc=pass (p=NONE sp=NONE dis=NONE)
 header.from=gmail.com
Return-Path: <[email protected]>
Received: from mail-yw0-x22b.google.com (mail-yw0-x22b.google.com.
 [2607:f8b0:4002:c05::22b]) by mx.google.com with ESMTPS id
 n66si796725ywe.36.2017.06.10.13.44.07 for <[email protected]>
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Jun
 2017 13:44:07 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates
 2607:f8b0:4002:c05::22b as permitted sender)
 client-ip=2607:f8b0:4002:c05::22b;
Authentication-Results: mx.google.com; dkim=pass [email protected]; spf=pass
 (google.com: domain of [email protected] designates 2607:f8b0:4002:c05::22b
 as permitted sender) [email protected]; dmarc=pass (p=NONE
 sp=NONE dis=NONE) header.from=gmail.com
Received: by mail-yw0-x22b.google.com with SMTP id v7so9270086ywc.2 for
 <[email protected]>; Sat, 10 Jun 2017 13:44:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=hTqw4/u5vB/cYxt7m8lnobdoP2XufhBU7f2IuwIJU4c=;
 b=aEZ6oCyObMtOBqNR4ldCTJ2yXethfeCjN94CKcoTP04+1IzBDWNlLmT1vyEtLruRZ2
 IW/1SeMmpn1V6+6gkPBbWWIWlauWLO9EZYU7ZE1VDuCfGJOFmAUvUcq004cO+kPHcJ37
 lKxggNKkmMP1GDmQiu2G3d8uPNHs0OR2dvvl9F4xkQknaIwSth2d6pY0+YSNyC7aiSUz
 mckLG1lGQID5MBsfkchX9HSv3kAQfQp1oOrn2gH3+k6W0BqPIv/hj4Zt6uJZnoxpBvx6
 FR0ubd02CWyRgqG5a89aI7PW/IIOZfGDpd+NKrQpy5IJdpkcW/h6//JrJhh4cUq1nc1R K9Lw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;
 s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=hTqw4/u5vB/cYxt7m8lnobdoP2XufhBU7f2IuwIJU4c=;
 b=S8e27ZIPWZ8/qWGo2Hm0Y+pRpa/19DWEkX/XZbcWXYJ5VxnM7VomBDXqqiXQ8CI0rB
 Vy0+NVyaYKcWqovA75i1AEiW8YbCU2pwhDsfmLKpduXVN18Tbjft3qNgJY5OIZppnf7n
 N6OtkBf78aYBwIhzqsDCGG4UyqxSDv8JIwwy6cBPj+Lwvs53tDaqRZTqHWoIGEyt+aCe
 5OYt3NiE1P0TjpTSsycm/exzsFURx/mzy1Pjj0jXpucvtLUF/KuyIM2CXkPTeygocTv9
 aID/2uDYEFin5ta9wcOixhFhtVRtXSUxSpGpDBNzWzZ6/jxyi9oRIGbDh/S0GZ9Hvm2w /8bg==
X-Gm-Message-State: AODbwcC7K9IzZrOa0JkKnzcl4saRJDpuoADuFq19EQve6maCjY1cxS4i
 gIgGOdXUEx/lVIszoL81pjAYuEFfW9xPkDg=
X-Received: by 10.129.49.202 with SMTP id x193mr15829756ywx.149.1497127447341;
 Sat, 10 Jun 2017 13:44:07 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.83.17.4 with HTTP; Sat, 10 Jun 2017 13:44:07 -0700 (PDT)
From: Denis Bondarenko <[email protected]>
Date: Sat, 10 Jun 2017 23:44:07 +0300
Message-ID: <CALvPciUkK_K9xPSuUjy0aNsHF4QLrEwb5V40abTaQQrVp8gi-w@mail.gmail.com>
Subject: This is a simple text
To: [email protected]
Content-Type: multipart/alternative; boundary="001a11421dacaeb3400551a125c6"

 BODY[2] {140}
<div dir="ltr"><span style="font-size:13px;background-color:rgb(245,245,245)">Your recipient seems to have encryption set up!</span></div>
 BODY[1] {49}
Your recipient seems to have encryption set up!

But for such a message, js.mime_decode () does not parse text (mimeMessage.getText () == null and mimeMessage.getHtml () == null).

What should I do? Should I leave everything as is now (load the whole message) or we will work on how to manually download the message from the server without attachments to make the download faster and use Js tools.

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

from flowcrypt-android.

tomholub avatar tomholub commented on July 24, 2024

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024
Is it possible to use the structure call and then selectively pull headers
+ textual content without pulling attachments that put together still look
like a MIME message?

I tried to do it, but the structure of the answers is different. Probably on this Js does not parse the answer.
raw_message_without_attachments.txt
whole_raw_message.txt

Tomorrow I'll try to see more options.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

Is it possible to use the structure call and then selectively pull headers

  • textual content without pulling attachments that put together still look
    like a MIME message? If yes, you can download and use that in
    js.mime_decode.

Yes. I did it in this commit d8521bc. I manually analyze the message structure and create a raw message with skipping body parts with attachments. I tested this solution and it works. I hope this helps us

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

At this point, you do not need to fix anything in your code.

from flowcrypt-android.

DenBond7 avatar DenBond7 commented on July 24, 2024

For me. Example of a message structure,

multipart/mixed                   1
        text/plain                    1.1
        application/msword            1.2
        message/rfc822                1.3
            multipart/alternative     1.3.TEXT
                text/plain            1.3.1
                multipart/related     1.3.2
                    text/html         1.3.2.1
                    image/png         1.3.2.2
                    image/png         1.3.2.3

from flowcrypt-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.