Skip to content

Commit

Permalink
Added a test version of sending encrypted message. (Compose variant).
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 9, 2017
1 parent ccdc569 commit 5eee60c
Show file tree
Hide file tree
Showing 31 changed files with 1,069 additions and 70 deletions.
4 changes: 4 additions & 0 deletions FlowCrypt/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.flowcrypt.email.ui.activity.EmailManagerActivity" />
</activity>
<activity
android:name=".ui.activity.SecureComposeActivity"
android:label="@string/title_activity_secure_compose"
android:theme="@style/AppTheme.NoActionBar" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class JavaEmailConstants {
public static final String MECHANISMS_TYPE_XOAUTH2 = "XOAUTH2";
public static final String GMAIL_IMAP_SERVER = "imap.gmail.com";
public static final String PROTOCOL_IMAP = "imap";
public static final String PROTOCOL_SMTP = "smtp";
public static final String PROTOCOL_GIMAPS = "gimaps";
public static final String OAUTH2 = "oauth2:";
public static final String MIME_TYPE_MULTIPART = "multipart/*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ public class GmailConstants {
public static final String PROPERTY_NAME_MAIL_GIMAPS_SSL_ENABLE = "mail.gimaps.ssl.enable";
public static final String PROPERTY_NAME_MAIL_GIMAPS_AUTH_MECHANISMS = "mail.gimaps.auth" +
".mechanisms";

public static final String PROPERTY_NAME_MAIL_SMTP_AUTH = "mail.smtp.auth";
public static final String PROPERTY_NAME_MAIL_SMTP_SSL_ENABLE = "mail.smtp.ssl.enable";
public static final String PROPERTY_NAME_MAIL_SMTP_AUTH_MECHANISMS = "mail.smtp.auth" +
".mechanisms";


public static final String HOST_SMTP_GMAIL_COM = "smtp.gmail.com";
public static final int PORT_SMTP_GMAIL_COM = 465;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.flowcrypt.email.api.email.model;

import android.os.Parcel;

import java.util.ArrayList;
import java.util.Date;

/**
* Simple POJO class which describe an incoming message model.
*
* @author DenBond7
* Date: 09.05.2017
* Time: 11:20
* E-mail: DenBond7@gmail.com
*/

public class IncomingMessageInfo extends MessageInfo {

public static final Creator<IncomingMessageInfo> CREATOR = new Creator<IncomingMessageInfo>() {
@Override
public IncomingMessageInfo createFromParcel(Parcel source) {
return new IncomingMessageInfo(source);
}

@Override
public IncomingMessageInfo[] newArray(int size) {
return new IncomingMessageInfo[size];
}
};

private ArrayList<String> from;
private Date receiveDate;

public IncomingMessageInfo() {
}

protected IncomingMessageInfo(Parcel in) {
super(in);
this.from = in.createStringArrayList();
long tmpReceiveDate = in.readLong();
this.receiveDate = tmpReceiveDate == -1 ? null : new Date(tmpReceiveDate);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeStringList(this.from);
dest.writeLong(this.receiveDate != null ? this.receiveDate.getTime() : -1);
}

/**
* Return a list of String which contain an information
* about from addresses.
*
* @return <tt>ArrayList<String></tt> The list of from addresses.
*/
public ArrayList<String> getFrom() {
return from;
}

public void setFrom(ArrayList<String> from) {
this.from = from;
}

public Date getReceiveDate() {
return receiveDate;
}

public void setReceiveDate(Date receiveDate) {
this.receiveDate = receiveDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.Date;

/**
* Simple POJO class which describe a message model.
*
Expand All @@ -16,10 +13,11 @@
*/

public class MessageInfo implements Parcelable {

public static final Creator<MessageInfo> CREATOR = new Creator<MessageInfo>() {
@Override
public MessageInfo createFromParcel(Parcel source) {
return new MessageInfo(source);
public MessageInfo createFromParcel(Parcel in) {
return new MessageInfo(in);
}

@Override
Expand All @@ -29,19 +27,14 @@ public MessageInfo[] newArray(int size) {
};

private String subject;
private ArrayList<String> from;
private String message;
private Date receiveDate;

public MessageInfo() {
}

protected MessageInfo(Parcel in) {
this.subject = in.readString();
this.from = in.createStringArrayList();
this.message = in.readString();
long tmpReceiveDate = in.readLong();
this.receiveDate = tmpReceiveDate == -1 ? null : new Date(tmpReceiveDate);
}

@Override
Expand All @@ -52,18 +45,14 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.subject);
dest.writeStringList(this.from);
dest.writeString(this.message);
dest.writeLong(this.receiveDate != null ? this.receiveDate.getTime() : -1);
}

@Override
public String toString() {
return "MessageInfo{" +
"subject='" + subject + '\'' +
", from=" + from +
", message='" + message + '\'' +
", receiveDate=" + receiveDate +
'}';
}

Expand All @@ -75,27 +64,11 @@ public void setSubject(String subject) {
this.subject = subject;
}

public ArrayList<String> getFrom() {
return from;
}

public void setFrom(ArrayList<String> from) {
this.from = from;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Date getReceiveDate() {
return receiveDate;
}

public void setReceiveDate(Date receiveDate) {
this.receiveDate = receiveDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.flowcrypt.email.api.email.model;

import android.os.Parcel;

import com.flowcrypt.email.test.PgpContact;

/**
* Simple POJO class which describe an outgoing message model.
*
* @author DenBond7
* Date: 09.05.2017
* Time: 11:20
* E-mail: DenBond7@gmail.com
*/

public class OutgoingMessageInfo extends MessageInfo {
public static final Creator<OutgoingMessageInfo> CREATOR = new Creator<OutgoingMessageInfo>() {
@Override
public OutgoingMessageInfo createFromParcel(Parcel source) {
return new OutgoingMessageInfo(source);
}

@Override
public OutgoingMessageInfo[] newArray(int size) {
return new OutgoingMessageInfo[size];
}
};
private PgpContact[] toPgpContacts;
private PgpContact fromPgpContact;

public OutgoingMessageInfo() {
}

protected OutgoingMessageInfo(Parcel in) {
super(in);
this.toPgpContacts = in.createTypedArray(PgpContact.CREATOR);
this.fromPgpContact = in.readParcelable(PgpContact.class.getClassLoader());
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeTypedArray(this.toPgpContacts, flags);
dest.writeParcelable(this.fromPgpContact, flags);
}

public PgpContact[] getToPgpContacts() {
return toPgpContacts;
}

public void setToPgpContacts(PgpContact[] toPgpContacts) {
this.toPgpContacts = toPgpContacts;
}

public PgpContact getFromPgpContact() {
return fromPgpContact;
}

public void setFromPgpContact(PgpContact fromPgpContact) {
this.fromPgpContact = fromPgpContact;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
*/

public class OpenStoreHelper {

/**
* Open and connect to the store using gimaps protocol.
*
* @param token An OAuth2 access token;
* @param accountName An account name which use to create connection;
* @return <tt>GmailSSLStore</tt> A GmailSSLStore object based on properties for
* gimaps.
*/

public static GmailSSLStore openAndConnectToGimapsStore(String token, String accountName) throws
MessagingException {

Expand All @@ -28,4 +38,15 @@ public static GmailSSLStore openAndConnectToGimapsStore(String token, String acc
gmailSSLStore.connect(JavaEmailConstants.GMAIL_IMAP_SERVER, accountName, token);
return gmailSSLStore;
}

/**
* Generate a session for gimaps protocol.
*
* @return <tt>Session</tt> A new session for gimaps protocol based on properties for gimaps.
*/
public static Session getGmailSession() {
Session session = Session.getInstance(PropertiesHelper.generatePropertiesForGimaps());
session.setDebug(BuildConfig.DEBUG);
return session;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,35 @@
*/

public class PropertiesHelper {

public static final String BOOLEAN_VALUE_TRUE = "true";

/**
* Generate properties for gimaps protocol.
*
* @return <tt>Properties</tt> New properties with setup gimaps connection;
*/
public static Properties generatePropertiesForGimaps() {
Properties properties = new Properties();
properties.put(GmailConstants.PROPERTY_NAME_MAIL_GIMAPS_SSL_ENABLE, "true");
properties.put(GmailConstants.PROPERTY_NAME_MAIL_GIMAPS_SSL_ENABLE, BOOLEAN_VALUE_TRUE);
properties.put(GmailConstants.PROPERTY_NAME_MAIL_GIMAPS_AUTH_MECHANISMS, JavaEmailConstants
.MECHANISMS_TYPE_XOAUTH2);

return properties;
}

/**
* Generate properties for gmail smtp connection.
*
* @return <tt>Properties</tt> New properties with setup gmail smtp connection;
*/
public static Properties generatePropertiesForGmailSmtp() {
Properties properties = new Properties();
properties.put(GmailConstants.PROPERTY_NAME_MAIL_SMTP_AUTH, BOOLEAN_VALUE_TRUE);
properties.put(GmailConstants.PROPERTY_NAME_MAIL_SMTP_SSL_ENABLE, BOOLEAN_VALUE_TRUE);
properties.put(GmailConstants.PROPERTY_NAME_MAIL_SMTP_AUTH_MECHANISMS, JavaEmailConstants
.MECHANISMS_TYPE_XOAUTH2);

return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public PostLookUpEmailModel[] newArray(int size) {
public PostLookUpEmailModel() {
}

public PostLookUpEmailModel(String email) {
this.email = email;
}

public PostLookUpEmailModel(Parcel in) {
this.email = in.readString();
}
Expand Down
Loading

0 comments on commit 5eee60c

Please sign in to comment.