5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-08 18:00:27 +00:00
envayasms/src/org/envaya/sms/IncomingMessage.java

70 lines
1.8 KiB
Java
Raw Normal View History

2011-09-22 23:16:46 +00:00
package org.envaya.sms;
2011-09-13 21:55:26 +00:00
import android.content.Intent;
import android.net.Uri;
2011-09-22 23:16:46 +00:00
import org.envaya.sms.receiver.IncomingMessageRetry;
2011-09-13 21:55:26 +00:00
2011-09-18 01:38:16 +00:00
public abstract class IncomingMessage extends QueuedMessage {
2011-09-13 21:55:26 +00:00
2011-09-18 01:38:16 +00:00
protected String from;
2011-09-18 01:38:16 +00:00
public IncomingMessage(App app, String from)
{
super(app);
this.from = from;
2011-09-18 01:38:16 +00:00
}
public abstract String getDisplayType();
public boolean isForwardable()
{
if (app.isTestMode() && !app.isTestPhoneNumber(from))
{
return false;
}
/*
* Don't forward messages from shortcodes or users with
* addresses like 'Vodacom' because they're likely to be
* messages from network, or spam. At least for network
* messages we should let them go in to the Messaging inbox
* because the person managing this phone needs to know
* when they're out of credit, etc.
*
* The minimum length of normal subscriber numbers doesn't
* seem to be specified, but in practice seems to be
* at least 7 digits everywhere.
*/
int fromDigits = 0;
int fromLength = from.length();
for (int i = 0; i < fromLength; i++)
{
if (Character.isDigit(from.charAt(i)))
{
fromDigits++;
}
}
return fromDigits >= 7;
}
2011-09-13 21:55:26 +00:00
public String getFrom()
{
return from;
2011-09-13 21:55:26 +00:00
}
public void retryNow() {
2011-09-18 01:38:16 +00:00
app.log("Retrying forwarding message from " + from);
2011-09-13 21:55:26 +00:00
tryForwardToServer();
2011-09-18 01:38:16 +00:00
}
2011-09-13 21:55:26 +00:00
protected Intent getRetryIntent() {
Intent intent = new Intent(app, IncomingMessageRetry.class);
2011-09-18 01:38:16 +00:00
intent.setData(this.getUri());
2011-09-13 21:55:26 +00:00
return intent;
2011-09-18 01:38:16 +00:00
}
public abstract void tryForwardToServer();
2011-09-13 21:55:26 +00:00
}