-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashMarkAsRead
More file actions
executable file
·64 lines (53 loc) · 2.62 KB
/
bashMarkAsRead
File metadata and controls
executable file
·64 lines (53 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
. bashCheckForCRFolder
#Bold colors
BWHITE='\033[1;37m'
BGREEN='\033[1;32m'
BRED='\033[1;31m'
BYELLOW='\033[1;33m'
BBLUE='\033[1;34m'
UBLUE='\033[4;34m'
NC='\033[0m' # No color
#create listFiles variable
listFiles="$(ls -d clientResourcesFolder/*essages.json 2>&1)"
lsError=$(cut -d ':' -f3 <<< $listFiles)
#Variable for messageId
messageId=
#Option for message ID
while getopts ":m:" option; do
case $option in
m) # give mailboxId
messageId=$OPTARG;;
\?) #Invalid option
echo "ERROR: Invalid option"
exit;;
esac
done
#Check if error exists, display message to run command for getting unread messages or date ranged messages if unreadMessages.json or date ranged messages json file does not exist
if [[ "$lsError" == " No such file or directory" ]] && ! [[ $messageId ]]
then
echo -e "\n${BWHITE}\"sea-client-nodejs/clientResourcesFolder/unreadMessages.json\"${BYELLOW} nor a date ranged messages file currently exist to pull a ${BWHITE}messageId ${BYELLOW}from ${BBLUE}${UBLUE}please run one of the below commands to pull unread messages for a ${NC}${BWHITE}messageId ${BBLUE}${UBLUE}before running this commmand again${NC}${BYELLOW} or enter ${BWHITE}7${BYELLOW} OR ${BWHITE}9${BYELLOW} from menu options when you run ${BGREEN}./bashMenu${BYELLOW}:"
echo -e "\n\n${BWHITE}Command: ${BGREEN}./bashCurlGetUnread\n"
echo -e "\n\n${BWHITE}Command: ${BGREEN}./bashGetMessagesByDateRange\n"
exit 1
fi
#While messageId variable empty prompt user of messageId
while ! [ $messageId ]; do
read -p "$(echo -e "\n${BYELLOW}Please enter ${BWHITE}messageId${BYELLOW} of message you want to mark as read from ${BWHITE}\"sea-client-nodejs/$checkFolder/unreadMessages.json\"${BYELLOW}:${NC} ")" messageId
done
#Set markAsRead variable to output of markFileRead command
markAsRead=$(node markFileRead -m $messageId)
#Set checkError variable to field 8 of cut string from markAsRead variable
checkError=$(cut -d ' ' -f8 <<< $markAsRead)
#See if Failed exists in checkError variable and if do display error message
if [ "$checkError" == "Failed" ]
then
echo -e "\n${BRED}ERROR: You have entered an ${BWHITE}invalid messageId or the messageId of a message that has already been marked as read${BRED}! Please run command again with a valid messageId."
echo -e "\n\n${BWHITE}Example: ${BGREEN}./bashMarkAsRead -m <messageId>${NC}\n"
echo -e "\n\n${NC}${BYELLOW}OR...${NC}"
echo -e "\n\n${NC}${BWHITE}Run this command and enter ${BBLUE}12${BWHITE} from Menu options: ${BGREEN}./bashMenu\n${NC}"
exit 1
#Else display success message
else
echo -e "\n\n\n${BGREEN}Successfully marked inbox record as read.${NC}\n\n\n"
fi