MCPcopy Create free account
hub / github.com/M66B/FairEmail / validate

Method validate

app/src/main/java/eu/faircode/email/EntityRule.java:703–805  ·  view source on GitHub ↗
(Context context)

Source from the content-addressed store, hash-verified

701 }
702
703 void validate(Context context) throws JSONException, IllegalArgumentException {
704 try {
705 Expression expression = ExpressionHelper.getExpression(this, null, null, null, context);
706 if (expression != null)
707 ExpressionHelper.check(expression);
708 } catch (ParseException | MessagingException ex) {
709 Log.w("EXPR", ex);
710 String message = ex.getMessage();
711 if (TextUtils.isEmpty(message))
712 message = "Invalid expression";
713 throw new IllegalArgumentException(message, ex);
714 }
715
716 JSONObject jargs = new JSONObject(action);
717 int type = jargs.getInt("type");
718
719 DB db = DB.getInstance(context);
720 switch (type) {
721 case TYPE_NOOP:
722 return;
723 case TYPE_SEEN:
724 return;
725 case TYPE_UNSEEN:
726 return;
727 case TYPE_HIDE:
728 return;
729 case TYPE_IGNORE:
730 return;
731 case TYPE_SNOOZE:
732 return;
733 case TYPE_FLAG:
734 return;
735 case TYPE_IMPORTANCE:
736 return;
737 case TYPE_KEYWORD:
738 String keyword = jargs.optString("keyword");
739 if (TextUtils.isEmpty(keyword))
740 throw new IllegalArgumentException(context.getString(R.string.title_rule_keyword_missing));
741 return;
742 case TYPE_MOVE:
743 case TYPE_COPY:
744 long target = jargs.optLong("target", -1);
745 if (target < 0)
746 throw new IllegalArgumentException(context.getString(R.string.title_rule_folder_missing));
747 EntityFolder folder = db.folder().getFolder(target);
748 if (folder == null)
749 throw new IllegalArgumentException("Folder not found");
750 return;
751 case TYPE_ANSWER:
752 long iid = jargs.optLong("identity", -1);
753 if (iid < 0)
754 throw new IllegalArgumentException(context.getString(R.string.title_rule_identity_missing));
755 EntityIdentity identity = db.identity().getIdentity(iid);
756 if (identity == null)
757 throw new IllegalArgumentException("Identity not found");
758
759 long aid = jargs.optLong("answer", -1);
760 if (aid < 0) {

Callers 2

onExecuteMethod · 0.95
onExecuteMethod · 0.95

Calls 15

getExpressionMethod · 0.95
checkMethod · 0.95
wMethod · 0.95
getInstanceMethod · 0.95
folderMethod · 0.95
identityMethod · 0.95
parseAddressesMethod · 0.95
answerMethod · 0.95
getAnswerMethod · 0.80
getMessageMethod · 0.65
getFolderMethod · 0.65
getIdentityMethod · 0.65

Tested by

no test coverage detected