use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.
the class EmailListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set the action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
// Initialize variables
mHelper = new I2PAndroidHelper(this);
mSharedPrefs = getSharedPreferences(Constants.SHARED_PREFS, 0);
mAccountHeader = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.drawer_header_background).withSelectionListEnabledForSingleProfile(false).addProfiles(getLockedProfile()).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
if (profile.getIdentifier() == ID_LOCKED)
findViewById(R.id.action_log_in).performClick();
else if (!currentProfile)
identitySelected(profile);
return false;
}
}).withSavedInstance(savedInstanceState).build();
IDrawerItem addressBook = new PrimaryDrawerItem().withIdentifier(ID_ADDRESS_BOOK).withName(R.string.address_book).withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_contacts).colorRes(R.color.md_grey_600).sizeDp(24)).withIconTintingEnabled(true).withSelectedIconColorRes(R.color.primary);
IDrawerItem networkStatus = getNetStatusItem(R.string.network_status, GoogleMaterial.Icon.gmd_cloud_off, R.color.md_grey_600, 0);
// Set the drawer width per Material design spec
// http://www.google.com/design/spec/layout/structure.html#structure-side-nav-1
// Mobile: side nav width = min(screen width - app bar height, 320dp)
// Desktop: side nav width = min(screen width - app bar height, 400dp)
int maxWidth = getResources().getDimensionPixelSize(R.dimen.nav_max_width);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int drawerWidth = Math.min(dm.widthPixels - toolbar.getLayoutParams().height, maxWidth);
mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withDrawerWidthPx(drawerWidth).withShowDrawerOnFirstLaunch(true).withAccountHeader(mAccountHeader).addStickyDrawerItems(addressBook, networkStatus).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
long id = iDrawerItem.getIdentifier();
if (id == ID_ADDRESS_BOOK) {
mDrawer.setSelection(mSelected, false);
mDrawer.closeDrawer();
Intent ai = new Intent(EmailListActivity.this, AddressBookActivity.class);
startActivity(ai);
return true;
} else if (id == ID_NET_STATUS) {
mDrawer.setSelection(mSelected, false);
netStatusSelected();
return true;
} else {
drawerFolderSelected((EmailFolder) iDrawerItem.getTag(), mSelected == i);
mSelected = mDrawer.getCurrentSelection();
return false;
}
}
}).withSavedInstance(savedInstanceState).build();
mSelected = mDrawer.getCurrentSelection();
// Enable ActionBar app icon to behave as action to toggle nav drawer
// noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
mDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
if (savedInstanceState == null) {
EmailListFragment f = EmailListFragment.newInstance("inbox");
getSupportFragmentManager().beginTransaction().add(R.id.list_fragment, f).commit();
}
// If first start, go to introduction and setup wizard
if (mSharedPrefs.getBoolean(PREF_FIRST_START, true)) {
mSharedPrefs.edit().putBoolean(PREF_FIRST_START, false).apply();
Intent i = new Intent(EmailListActivity.this, IntroActivity.class);
startActivityForResult(i, SHOW_INTRODUCTION);
}
}
use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.
the class BoteService method emailReceived.
// NewEmailListener
@Override
public void emailReceived(String messageId) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder b = new NotificationCompat.Builder(this).setAutoCancel(true).setSmallIcon(R.drawable.ic_notif).setDefaults(Notification.DEFAULT_ALL);
try {
EmailFolder inbox = I2PBote.getInstance().getInbox();
// Set the new email as \Recent
inbox.setRecent(messageId, true);
// Now display/update notification with all \Recent emails
List<Email> newEmails = BoteHelper.getRecentEmails(inbox);
int numNew = newEmails.size();
switch(numNew) {
case 0:
nm.cancel(NOTIF_ID_NEW_EMAIL);
return;
case 1:
Email email = newEmails.get(0);
String fromAddress = email.getOneFromAddress();
Bitmap picture = BoteHelper.getPictureForAddress(fromAddress);
if (picture != null)
b.setLargeIcon(picture);
else if (!email.isAnonymous()) {
int width = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_width);
int height = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_height);
b.setLargeIcon(BoteHelper.getIdenticonForAddress(fromAddress, width, height));
} else
b.setSmallIcon(R.drawable.ic_contact_picture);
b.setContentTitle(BoteHelper.getNameAndShortDestination(fromAddress));
b.setContentText(email.getSubject());
Intent vei = new Intent(this, ViewEmailActivity.class);
vei.putExtra(ViewEmailActivity.FOLDER_NAME, inbox.getName());
vei.putExtra(ViewEmailActivity.MESSAGE_ID, email.getMessageID());
vei.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pvei = PendingIntent.getActivity(this, 0, vei, PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(pvei);
break;
default:
b.setContentTitle(getResources().getQuantityString(R.plurals.n_new_emails, numNew, numNew));
HashSet<Address> recipients = new HashSet<Address>();
String bigText = "";
for (Email ne : newEmails) {
recipients.add(BoteHelper.getOneLocalRecipient(ne));
bigText += BoteHelper.getNameAndShortDestination(ne.getOneFromAddress());
bigText += ": " + ne.getSubject() + "\n";
}
b.setContentText(BoteHelper.joinAddressNames(recipients));
b.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
Intent eli = new Intent(this, EmailListActivity.class);
eli.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent peli = PendingIntent.getActivity(this, 0, eli, PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(peli);
}
} catch (PasswordException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException 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();
}
nm.notify(NOTIF_ID_NEW_EMAIL, b.build());
}
use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.
the class MapperFactory method getMailboxes.
/**
* Maps mailbox names to mailboxes.
*/
private Map<String, BoteMailbox> getMailboxes() {
// XXX: When user folders are set up, this will need to be updated.
if (mailboxes.isEmpty()) {
for (EmailFolder folder : folderManager.getEmailFolders()) {
String folderName = folder.getName().toLowerCase();
mailboxes.put(folderName, new BoteMailbox(folder, uidValidity, MessageUid.MIN_VALUE));
}
}
return mailboxes;
}
use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.
the class I2PBote method initializeFolderAccess.
/**
* Initializes objects for accessing emails and packet files on the filesystem.
* @param passwordCache
*/
private void initializeFolderAccess(PasswordCache passwordCache) {
inbox = new EmailFolder(configuration.getInboxDir(), passwordCache);
outbox = new Outbox(configuration.getOutboxDir(), passwordCache);
sentFolder = new EmailFolder(configuration.getSentFolderDir(), passwordCache);
trashFolder = new TrashFolder(configuration.getTrashFolderDir(), passwordCache);
relayPacketFolder = new RelayPacketFolder(configuration.getRelayPacketDir());
MessageIdCache messageIdCache = new MessageIdCache(configuration.getMessageIdCacheFile(), configuration.getMessageIdCacheSize());
incompleteEmailFolder = new IncompleteEmailFolder(configuration.getIncompleteDir(), messageIdCache, inbox);
emailDhtStorageFolder = new EmailPacketFolder(configuration.getEmailDhtStorageDir());
indexPacketDhtStorageFolder = new IndexPacketFolder(configuration.getIndexPacketDhtStorageDir());
directoryDhtFolder = new DirectoryEntryFolder(configuration.getDirectoryEntryDhtStorageDir());
}
use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.
the class AttachmentProviderTests method tearDown.
@After
public void tearDown() throws Exception {
super.tearDown();
EmailFolder inbox = I2PBote.getInstance().getInbox();
for (Email email : BoteHelper.getEmails(inbox, null, true)) {
inbox.delete(email.getMessageID());
}
System.setProperty("i2pbote.initialized", "false");
}
Aggregations