(EntityMessage message)
| 642 | } |
| 643 | |
| 644 | private void onSend(EntityMessage message) throws JSONException, MessagingException, IOException { |
| 645 | DB db = DB.getInstance(this); |
| 646 | |
| 647 | // Check if cancelled by user or by errors |
| 648 | EntityOperation operation = db.operation().getOperation(message.id, EntityOperation.SEND); |
| 649 | if (operation == null) |
| 650 | return; |
| 651 | |
| 652 | // Mark attempt |
| 653 | if (message.last_attempt == null) { |
| 654 | message.last_attempt = new Date().getTime(); |
| 655 | db.message().setMessageLastAttempt(message.id, message.last_attempt); |
| 656 | } |
| 657 | |
| 658 | NotificationManager nm = Helper.getSystemService(this, NotificationManager.class); |
| 659 | if (NotificationHelper.areNotificationsEnabled(nm)) |
| 660 | nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(true)); |
| 661 | |
| 662 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| 663 | boolean send_partial = prefs.getBoolean("send_partial", false); |
| 664 | boolean reply_move = prefs.getBoolean("reply_move", false); |
| 665 | boolean reply_move_inbox = prefs.getBoolean("reply_move_inbox", true); |
| 666 | boolean protocol = prefs.getBoolean("protocol", false); |
| 667 | boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG); |
| 668 | |
| 669 | if (message.identity == null) |
| 670 | throw new IllegalArgumentException("Send without identity"); |
| 671 | if (!message.content) |
| 672 | throw new IllegalArgumentException("Message body missing"); |
| 673 | |
| 674 | EntityAccount account = db.account().getAccount(message.account); |
| 675 | |
| 676 | EntityIdentity ident = db.identity().getIdentity(message.identity); |
| 677 | if (ident == null) |
| 678 | throw new IllegalArgumentException("Identity not found"); |
| 679 | if (!ident.synchronize) |
| 680 | throw new IllegalArgumentException("Identity is disabled"); |
| 681 | |
| 682 | // Update message ID |
| 683 | if (message.from != null && message.from.length > 0) { |
| 684 | String from = ((InternetAddress) message.from[0]).getAddress(); |
| 685 | int at = (from == null ? -1 : from.indexOf('@')); |
| 686 | if (at > 0 && at + 1 < from.length()) |
| 687 | message.msgid = EntityMessage.generateMessageId(from.substring(at + 1)); |
| 688 | } |
| 689 | |
| 690 | // Set sent time |
| 691 | message.sent = new Date().getTime(); |
| 692 | db.message().setMessageSent(message.id, message.sent); |
| 693 | |
| 694 | // Create message |
| 695 | Properties props = MessageHelper.getSessionProperties(ident.unicode); |
| 696 | Session isession = Session.getInstance(props, null); |
| 697 | MimeMessage imessage = MessageHelper.from(this, message, ident, isession, true); |
| 698 | |
| 699 | // Prepare sent message |
| 700 | Long sid = null; |
| 701 | EntityFolder sent = null; |
no test coverage detected