├── .gitignore ├── .pre-commit-config.yaml ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main └── java │ └── org │ └── rm3l │ └── maoni │ └── email │ └── MaoniEmailListener.java └── test └── java └── org └── rm3l └── maoni └── email └── MaoniEmailListenerTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Armel Soro 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | # 23 | 24 | *.iml 25 | .gradle 26 | /local.properties 27 | /.idea/workspace.xml 28 | /.idea/libraries 29 | .DS_Store 30 | /build 31 | /captures 32 | 33 | **/*.class 34 | 35 | # Mobile Tools for Java (J2ME) 36 | **/.mtj.tmp/ 37 | 38 | libraries/**/build 39 | build 40 | .gradle 41 | 42 | **/*.apk 43 | 44 | 45 | samples 46 | #DEPLOYMENT 47 | 48 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 49 | **/hs_err_pid* 50 | .idea 51 | actionbarsherlock 52 | **/*.iml 53 | local.properties 54 | 55 | 56 | .DS_Store 57 | 58 | # Built application files 59 | *.apk 60 | *.ap_ 61 | 62 | # Files for the Dalvik VM 63 | *.dex 64 | 65 | # Java class files 66 | *.class 67 | 68 | # Generated files 69 | bin/ 70 | gen/ 71 | 72 | # Gradle files 73 | .gradle/ 74 | build/ 75 | 76 | # Local configuration file (sdk path, etc) 77 | local.properties 78 | 79 | # Proguard folder generated by Eclipse 80 | proguard/ 81 | 82 | # Log Files 83 | *.log 84 | 85 | # Android Studio Navigation editor temp files 86 | .navigation/ 87 | 88 | # Android Studio captures folder 89 | captures/ 90 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/thlorenz/doctoc 3 | sha: master 4 | hooks: 5 | - id: doctoc 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Armel Soro 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | # 23 | 24 | language: java 25 | 26 | jdk: 27 | - openjdk8 28 | 29 | before_cache: 30 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 31 | - rm -rf $HOME/.gradle/caches/*/plugin-resolution/ 32 | cache: 33 | directories: 34 | - $HOME/.gradle/caches/ 35 | - $HOME/.gradle/wrapper/ 36 | 37 | script: 38 | - echo "Travis branch is $TRAVIS_BRANCH, and is in pull request $TRAVIS_PULL_REQUEST" 39 | - ./gradlew clean check assemble --stacktrace 40 | 41 | notifications: 42 | email: 43 | - apps+maoni-email__builds@rm3l.org 44 | 45 | sudo: false 46 | 47 | after_success: 48 | - bash <(curl -s https://codecov.io/bash) 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Armel Soro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *ARCHIVED*. This has been merged to the main 'Maoni' project. Now available at https://github.com/maoni-app/maoni/tree/master/callbacks/maoni-email 2 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Armel Soro 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | final homePath = System.properties['user.home'] 23 | 24 | buildscript { 25 | repositories { 26 | jcenter() 27 | google() 28 | } 29 | dependencies { 30 | classpath 'com.android.tools.build:gradle:3.2.0-alpha04' 31 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' 32 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 33 | // NOTE: Do not place your application dependencies here; they belong 34 | // in the individual module build.gradle files 35 | } 36 | } 37 | 38 | allprojects { 39 | repositories { 40 | jcenter() 41 | google() 42 | } 43 | } 44 | 45 | apply plugin: 'java' 46 | apply plugin: 'com.jfrog.bintray' 47 | apply plugin: 'com.github.dcendents.android-maven' 48 | 49 | targetCompatibility = '1.7' 50 | sourceCompatibility = '1.7' 51 | 52 | group = 'org.rm3l' 53 | version = '3.1.0-maoni_6.0.0' 54 | 55 | dependencies { 56 | implementation 'org.rm3l:maoni-common:6.0.0' 57 | //We are interacting with Android components for sending emails 58 | compileOnly ('com.google.android:android:4.1.1.4') { 59 | exclude group: 'org.json', module: 'json' 60 | } 61 | implementation fileTree(dir: 'libs', include: ['*.jar']) 62 | testImplementation 'junit:junit:4.12' 63 | } 64 | 65 | task generateSourcesJar(type: Jar) { 66 | classifier 'sources' 67 | } 68 | 69 | task generateJavadocs(type: Javadoc) { 70 | failOnError false 71 | } 72 | 73 | task generateJavadocsJar(type: Jar) { 74 | from generateJavadocs.destinationDir 75 | classifier 'javadoc' 76 | } 77 | 78 | generateJavadocsJar.dependsOn generateJavadocs 79 | 80 | artifacts { 81 | archives generateJavadocsJar 82 | archives generateSourcesJar 83 | } 84 | 85 | bintray { 86 | 87 | //Attempt to read keystore.properties file, if any first 88 | final propsFile = new File(homePath.toString() + "/.droid/", "maoni.bintray.properties") 89 | 90 | if (propsFile.exists()) { 91 | printf("[Bintray] Using properties file located at " + propsFile.absolutePath) 92 | final props = new Properties() 93 | props.load(new FileInputStream(propsFile)) 94 | user = props['user'] 95 | key = props['key'] 96 | } else { 97 | user = "" 98 | key = "" 99 | } 100 | 101 | publish = true //If version should be auto published after an upload 102 | 103 | pkg { 104 | repo = 'maven' 105 | name = 'org.rm3l:maoni-email' 106 | labels = ['maoni', 'android', 'feedback', 'android-lib', 'comments', 'review', 'bug', 'issue'] 107 | 108 | //noinspection GroovyAssignabilityCheck 109 | version { 110 | name = '3.1.0-maoni_6.0.0' 111 | desc = 'Maoni Android Library - Email Handler' 112 | released = new Date() 113 | vcsTag = '3.1.0-maoni_6.0.0' 114 | } 115 | 116 | publicDownloadNumbers = true 117 | 118 | licenses = ['MIT'] 119 | vcsUrl = 'https://github.com/rm3l/maoni-email.git' 120 | websiteUrl = 'https://github.com/rm3l/maoni-email' 121 | issueTrackerUrl = 'https://github.com/rm3l/maoni-email/issues' 122 | 123 | } 124 | configurations = ['archives'] 125 | } 126 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rm3l/maoni-email/afc39f24ba05f31ad69c5877f96b42571e2f507e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Sep 10 15:04:06 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/java/org/rm3l/maoni/email/MaoniEmailListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Armel Soro 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package org.rm3l.maoni.email; 23 | 24 | import android.content.ComponentName; 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.net.Uri; 28 | import android.os.Build; 29 | 30 | import org.rm3l.maoni.common.contract.Listener; 31 | import org.rm3l.maoni.common.model.Feedback; 32 | 33 | import java.util.ArrayList; 34 | import java.util.Map; 35 | 36 | /** 37 | * Simple callback for Maoni that takes care of sending the Feedback via an email provider 38 | */ 39 | public class MaoniEmailListener implements Listener { 40 | 41 | public static final String DEFAULT_EMAIL_SUBJECT = "Feedback"; 42 | 43 | private final Context mContext; 44 | private final String mMimeType; 45 | private final String mSubject; 46 | private final String[] mToAddresses; 47 | private final String mBodyHeader; 48 | private final String mBodyFooter; 49 | private final String[] mCcAddresses; 50 | private final String[] mBccAddresses; 51 | 52 | public MaoniEmailListener(final Context context, final String... toAddresses) { 53 | this(context, DEFAULT_EMAIL_SUBJECT, toAddresses); 54 | } 55 | 56 | public MaoniEmailListener(final Context context, final String subject, 57 | final String[] toAddresses) { 58 | this(context, subject, toAddresses, null, null); 59 | } 60 | 61 | public MaoniEmailListener(final Context context, final String subject, 62 | final String[] toAddresses, final String[] ccAddresses, final String[] bccAddresses) { 63 | this(context, "text/html", subject, null, null, toAddresses, ccAddresses, bccAddresses); 64 | } 65 | 66 | public MaoniEmailListener( 67 | final Context context, 68 | final String mimeType, 69 | final String subject, 70 | final String bodyHeader, 71 | final String bodyFooter, 72 | final String[] toAddresses, 73 | final String[] ccAddresses, 74 | final String[] bccAddresses) { 75 | this.mContext = context; 76 | this.mMimeType = mimeType; 77 | this.mSubject = subject; 78 | this.mToAddresses = toAddresses; 79 | this.mBodyHeader = bodyHeader; 80 | this.mBodyFooter = bodyFooter; 81 | this.mCcAddresses = ccAddresses; 82 | this.mBccAddresses = bccAddresses; 83 | } 84 | 85 | @Override 86 | public void onDismiss() { 87 | //Nothing to do 88 | } 89 | 90 | @Override 91 | public boolean onSendButtonClicked(final Feedback feedback) { 92 | 93 | final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); 94 | intent.setData(Uri.parse("mailto:")); // only email apps should handle this 95 | intent.putExtra(Intent.EXTRA_SUBJECT, 96 | mSubject != null ? mSubject : DEFAULT_EMAIL_SUBJECT); 97 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { 98 | if (mToAddresses != null) { 99 | intent.putExtra(Intent.EXTRA_EMAIL, mToAddresses); 100 | } 101 | if (mCcAddresses != null) { 102 | intent.putExtra(Intent.EXTRA_CC, mCcAddresses); 103 | } 104 | if (mBccAddresses != null) { 105 | intent.putExtra(Intent.EXTRA_BCC, mBccAddresses); 106 | } 107 | } 108 | if (mMimeType != null) { 109 | intent.setType(mMimeType); 110 | } 111 | 112 | final StringBuilder body = new StringBuilder(); 113 | if (mBodyHeader != null) { 114 | body.append(mBodyHeader).append("\n\n"); 115 | } 116 | 117 | body.append(feedback.userComment).append("\n\n"); 118 | 119 | body.append("\n------------\n"); 120 | body.append("- Feedback ID: ").append(feedback.id).append("\n"); 121 | 122 | final Map additionalData = feedback.getAdditionalData(); 123 | if (additionalData != null) { 124 | body.append("\n------ Extra-fields ------\n"); 125 | for (final Map.Entry entry : additionalData.entrySet()) { 126 | body.append("- ") 127 | .append(entry.getKey()).append(": "). 128 | append(entry.getValue()).append("\n"); 129 | } 130 | } 131 | 132 | body.append("\n------ Application ------\n"); 133 | if (feedback.appInfo != null) { 134 | if (feedback.appInfo.applicationId != null) { 135 | body.append("- Application ID: ").append(feedback.appInfo.applicationId).append("\n"); 136 | } 137 | if (feedback.appInfo.caller != null) { 138 | body.append("- Activity: ").append(feedback.appInfo.caller).append("\n"); 139 | } 140 | if (feedback.appInfo.buildType != null) { 141 | body.append("- Build Type: ").append(feedback.appInfo.buildType).append("\n"); 142 | } 143 | if (feedback.appInfo.flavor != null) { 144 | body.append("- Flavor: ").append(feedback.appInfo.flavor).append("\n"); 145 | } 146 | if (feedback.appInfo.versionCode != null) { 147 | body.append("- Version Code: ").append(feedback.appInfo.versionCode).append("\n"); 148 | } 149 | if (feedback.appInfo.versionName != null) { 150 | body.append("- Version Name: ").append(feedback.appInfo.versionName).append("\n"); 151 | } 152 | } 153 | 154 | body.append("\n------ Device ------\n"); 155 | if (feedback.deviceInfo != null) { 156 | body.append(feedback.deviceInfo.toString()); 157 | } 158 | body.append("\n\n"); 159 | 160 | if (mBodyFooter != null) { 161 | body.append("\n--").append(mBodyFooter); 162 | } 163 | 164 | intent.putExtra(Intent.EXTRA_TEXT, body.toString()); 165 | 166 | final ComponentName componentName = intent.resolveActivity(mContext.getPackageManager()); 167 | if (componentName != null) { 168 | //Add screenshot as attachment 169 | final ArrayList attachmentsUris = new ArrayList<>(); 170 | if (feedback.screenshotFileUri != null) { 171 | //Grant READ permission to the intent 172 | mContext.grantUriPermission(componentName.getPackageName(), 173 | feedback.screenshotFileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); 174 | attachmentsUris.add(feedback.screenshotFileUri); 175 | } 176 | //Add logs file as attachment 177 | if (feedback.logsFileUri != null) { 178 | //Grant READ permission to the intent 179 | mContext.grantUriPermission(componentName.getPackageName(), 180 | feedback.logsFileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); 181 | attachmentsUris.add(feedback.logsFileUri); 182 | } 183 | if (!attachmentsUris.isEmpty()) { 184 | intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentsUris); 185 | } 186 | mContext.startActivity(intent); 187 | } 188 | 189 | return true; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/test/java/org/rm3l/maoni/email/MaoniEmailListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Armel Soro 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package org.rm3l.maoni.email; 23 | 24 | /** 25 | * TODO Write tests 26 | */ 27 | public class MaoniEmailListenerTest { 28 | } 29 | --------------------------------------------------------------------------------