Fully display emails

This commit is contained in:
str4d
2014-02-28 07:29:55 +00:00
parent b5d32c0cc3
commit 04f0958f07
4 changed files with 175 additions and 12 deletions

View File

@@ -1,5 +1,10 @@
package i2p.bote;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.text.DateFormat;
import javax.mail.Address;
import javax.mail.MessagingException;
import i2p.bote.email.Email;
@@ -10,6 +15,7 @@ import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ViewEmailFragment extends Fragment {
@@ -39,27 +45,64 @@ public class ViewEmailFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_view_email, container, false);
TextView subject = (TextView) v.findViewById(R.id.email_subject);
try {
Email e = BoteHelper.getEmail(mFolderName, mMessageId);
if (e != null) {
subject.setText(e.getSubject());
displayEmail(e, v);
} else {
TextView subject = (TextView) v.findViewById(R.id.email_subject);
subject.setText("Email not found");
}
} catch (PasswordException e) {
// TODO: Handle
e.printStackTrace();
} catch (MessagingException e) {
// TODO Handle
e.printStackTrace();
}
return v;
}
public String getMessageId() {
return mMessageId;
private void displayEmail(Email email, View v) {
TextView subject = (TextView) v.findViewById(R.id.email_subject);
TextView sender = (TextView) v.findViewById(R.id.email_sender);
LinearLayout recipients = (LinearLayout) v.findViewById(R.id.email_recipients);
TextView sent = (TextView) v.findViewById(R.id.email_sent);
TextView received = (TextView) v.findViewById(R.id.email_received);
TextView content = (TextView) v.findViewById(R.id.email_content);
try {
subject.setText(email.getSubject());
sender.setText(BoteHelper.getDisplayAddress(
email.getOneFromAddress()));
for (Address recipient : email.getToAddresses()) {
TextView tv = new TextView(getActivity());
tv.setText(BoteHelper.getDisplayAddress(recipient.toString()));
recipients.addView(tv);
}
if (email.getSentDate() != null)
sent.setText(DateFormat.getInstance().format(
email.getSentDate()));
if (email.getReceivedDate() != null)
received.setText(DateFormat.getInstance().format(
email.getReceivedDate()));
content.setText(email.getText());
} catch (MessagingException e) {
// TODO Handle
e.printStackTrace();
} catch (PasswordException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -1,6 +1,10 @@
package i2p.bote.util;
import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.mail.MessagingException;
import android.content.Context;
import i2p.bote.R;
@@ -42,4 +46,14 @@ public class BoteHelper extends GeneralHelper {
return displayName;
}
public static String getDisplayAddress(String address) throws PasswordException, IOException, GeneralSecurityException, MessagingException {
String fullAdr = getNameAndDestination(address);
String emailDest = extractEmailDestination(fullAdr);
String name = extractName(fullAdr);
return (emailDest == null ? address
: (name.isEmpty() ? emailDest.substring(0, 10)
: name + " <" + emailDest.substring(0, 10) + "...>"));
}
}