📄 hushapplet.java
字号:
add(commands,commandsConstraints,backButton,0,0); add(commands,commandsConstraints,clearButton,1,0); add(commands,commandsConstraints,saveDraftButton,2,0); add(commands,commandsConstraints,sendButton,3,0); currentScreen = "compose"; mainLayout.show(main,currentScreen); commands.paintAll(commands.getGraphics()); } /* On click of the "Addresses" button */ else if (y>=215 && y<=240 && x>=43 && x<=67 && !currentScreen.equals("addresses") && !lockMenu) { if (currentScreen.equals("read")) c.wipeMessage(); clearCommands(); add(commands,commandsConstraints,newAddressButton,0,0); add(commands,commandsConstraints,showFingerprintButton,1,0); currentScreen = "addresses"; mainLayout.show(main,currentScreen); commands.paintAll(commands.getGraphics()); } /* On click of the "Quit" button */ else if (y>=280 && y<=305 && x>=43 && x<=67 && !lockMenu) { lockButtons(true); clearCommands(); add(commands,commandsConstraints, new Label("Quitting " +" " ),0,0); commands.paintAll(commands.getGraphics()); try { c.use(); c.quit(); } catch (IOException e1) {System.out.println("Connection closed");} try { URL u = new URL(exitpage+"?action=Quit&username="+c.username()); getAppletContext().showDocument(u); c.wipeMessage(); c.killPassCipher(); removeAll(); paintAll(getGraphics()); } catch (MalformedURLException mue) {System.out.println("Malformed URL");} stop(); } return true; } public boolean action(Event e, Object o) { /** * Overrides Applet.action * This method handles actions: button clicks and text component return presses */ /* Update rotateCount for ad changes */ rotateCount=rotateCount+(keyStrokesPerAdRotation/clicksPerAdRotation); /* The statusBar is cleared with each new action event */ statusBar.removeAll(); /* If a passphrase has been entered init2 is called */ if ((e.target==passphraseField || e.target==passphraseButton) && passphraseField.getText().length()>0) init2(); /* On click of the "Select All" button */ else if (e.target==selectAllButton) { /* Action is that all items on the pages are marked as selected. * In the event that all items are already selected, all items * are unselected */ /* If it's a selection of folders */ if (currentScreen.equals("listFolders")) { if (foldersSelected()<numberOfFoldersDisplayed) for (int x=currentFolderPage*linesPerPage;x<currentFolderPage*linesPerPage+numberOfFoldersDisplayed;x++) selectFolder(x); else for (int x=currentFolderPage*linesPerPage;x<currentFolderPage*linesPerPage+numberOfFoldersDisplayed;x++) unselectFolder(x); showSelectFunctionButtons(foldersSelected()>0,2); } /* If it's a selection of messages */ else if (currentScreen.equals("listMessages")) { if (messagesSelected()<numberOfMessagesDisplayed) for (int x=currentMessagePage*linesPerPage;x<currentMessagePage*linesPerPage+numberOfMessagesDisplayed;x++) selectMessage(x); else for (int x=currentMessagePage*linesPerPage;x<currentMessagePage*linesPerPage+numberOfMessagesDisplayed;x++) unselectMessage(x); showSelectFunctionButtons(messagesSelected()>0,1); } } /* On click of the "Clear" button wipe all fields on compose screen */ else if (e.target==clearButton) { confirmLabel.setText("Are you sure you want to clear this message?"); clearCommands(); lockButtons(true); add(commands,commandsConstraints,confirmLabel,0,0); add(commands,commandsConstraints,confirmDeleteButton,1,0); add(commands,commandsConstraints,cancelDeleteButton,2,0); commands.paintAll(commands.getGraphics()); } else if (e.target==showFingerprintButton) { if (smallApplet) statusBar(spaces+"Pub key fingerprint: "+c.fingerprint()+spaces); else statusBar(spaces+"Public key fingerprint: "+c.fingerprint()+spaces); } else if (e.target==saveDraftButton) { /* Saves a copy of the message currnetly being composed * in the "drafts" folder */ String ccs=""; /* A concatenation of headerFields with "Cc:" selected */ String tos=""; /* A concatenation of headerFields with "To:" selected */ String bccs=""; /* A concatenation of headerFields with "Bcc:" selected */ String ebcc=""; /* Iterate through to/cc/bcc fields to create headerInfo; */ for (int x=0;x<3;x++) { /* If a headerField contains an address */ if (headerField[x].getText().trim().length()>0) { /* If a headerField contains a valid address */ if (validEmailAddresses(headerField[x].getText())) { /* Sort address info into to, cc, or bcc strings */ if (fieldChoice[x].getSelectedItem().equals("To:")) tos=tos+headerField[x].getText().trim()+", "; else if (fieldChoice[x].getSelectedItem().equals("Cc:")) ccs=ccs+headerField[x].getText().trim()+", "; else bccs=bccs+headerField[x].getText().trim()+", "; } /* Exit if email address is invalid */ else { headerField[x].requestFocus(); return false; } } } clearCommands(); lockButtons(true); add(commands,commandsConstraints, new Label("Saving draft "+ " "),0,0); commands.paintAll(commands.getGraphics()); /* Sort message info into fields understood by * message decryption method in Connection.java */ if (tos.length()>0) tos="E-To: "+tos.substring(0,tos.length()-2)+"\n"; if (ccs.length()>0) ccs="E-Cc: "+ccs.substring(0,ccs.length()-2)+"\n"; if (bccs.length()>0) bccs="E-Bcc: "+bccs.substring(0,bccs.length()-2)+"\n"; /* Since message encryption takes arrays of headers and * recipients, info must be stored in arrays of length 1 */ String[] draftHeader = new String[1]; String[] draftRecipient = new String[1]; draftHeader[0]="From "+c.emailAddress()+" " +new Date().toString()+"\n"+cDate.getText().trim() +"\nSubject: "+cSubject.getText().trim()+"\nFrom: " +c.emailAddress()+"\n"+tos+ccs+bccs; draftRecipient[0]=c.username(); try { c.use(); c.sendEncryptedMessage(draftRecipient,draftHeader,cBody.getText(),true,"drafts"); if (c.folderName().equals("drafts")) listMessages("drafts",0,true); listFolders(currentFolderPage,true); c.done(); clearCommands(); add(commands,commandsConstraints,selectAllButton,0,0); currentScreen = "listMessages"; showSelectFunctionButtons(foldersSelected()>0,1); mainLayout.show(main,currentScreen); lockButtons(false); cBody.setText(" "); compose("","","","","",""); statusBar(spaces+"Draft saved"+spaces); } catch (IOException e0) { clearCommands(); lockButtons(false); add(commands,commandsConstraints,backButton,0,0); add(commands,commandsConstraints,clearButton,1,0); add(commands,commandsConstraints,saveDraftButton,2,0); add(commands,commandsConstraints,sendButton,3,0); currentScreen = "compose"; mainLayout.show(main,currentScreen); error(); } } /**** * The send routine. This is long **/ /* On click of the "Send" button send a message */ else if (e.target==sendButton) { /* Sends the message currently on the compose screen */ String headerInfo=""; String ccs=""; /* A concatenation of headerFields with "Cc:" selected */ String tos=""; /* A concatenation of headerFields with "To:" selected */ String bccs=""; /* A concatenation of headerFields with "Bcc:" selected */ String ebcc=""; boolean theresAnAddress = false; /* Iterate through to/cc/bcc fields to create headerInfo; */ for (int x=0;x<3;x++) { /* If a headerField contains an address */ if (headerField[x].getText().trim().length()>0) { theresAnAddress = true; /* If a headerField contains a valid address */ if (validEmailAddresses(headerField[x].getText())) { /* Sort address into to, cc, or bcc strings */ if (fieldChoice[x].getSelectedItem().equals("To:")) tos=tos+headerField[x].getText().trim()+", "; else if (fieldChoice[x].getSelectedItem().equals("Cc:")) ccs=ccs+headerField[x].getText().trim()+", "; else bccs=bccs+headerField[x].getText().trim()+", "; } /* Exit if email address is invalid */ else { headerField[x].requestFocus(); return false; } } } if (!theresAnAddress) { statusBar(spaces+"You must enter an address"+spaces); return false; } try { boolean wasSent=false; clearCommands(); lockButtons(true); /* If message should be encrypted */ if (encryptCheckbox.getState()) { add(commands,commandsConstraints, new Label("Encrypting and sending message " +" "),0,0); commands.paintAll(commands.getGraphics()); /* Save recipient information in "E-" headers so it can be parsed out later. * This is necessary because each recipient must receive a differently * encrypted copy of the message. */ if (tos.length()>0) tos="E-To: "+tos.substring(0,tos.length()-2)+"\n"; if (ccs.length()>0) ccs="E-Cc: "+ccs.substring(0,ccs.length()-2)+"\n"; if (bccs.length()>0) bccs="E-Bcc: "+bccs.substring(0,bccs.length()-2)+"\n"; /* Use vectors to store recipient and header info * This is important because each recipient will * receive the same message with different * header info. See Connection.sendEncryptedMessage */ Vector recipientsVector=new Vector(); Vector headersVector=new Vector(); String thisField=""; String thisAddress=""; int lastComma; boolean inQuotes; /* Parse individual recipients out of header fields * and store appropriate info in vectores */ for (int y=0;y<3;y++) { lastComma=-1; inQuotes=false; thisField = headerField[y].getText(); for (int x=0;x<thisField.length();x++) { if (thisField.regionMatches(x,"\"",0,1)) inQuotes=!inQuotes; else if (!inQuotes&&thisField.regionMatches(x,",",0,1)||x==thisField.length()-1) { if (x==thisField.length()-1) thisAddress=thisField.substring(lastComma+1,x+1).trim(); else thisAddress=thisField.substring(lastComma+1,x).trim(); ebcc=""; if (bccs.length()>0) if (bccs.indexOf(thisAddress)!=-1) ebcc="E-Bcc: "+thisAddress+"\n"; headersVector.addElement(cDate.getText().trim()+"\nSubject: "+cSubject.getText().trim() +"\nFrom: "+c.emailAddress()+"\nTo: "+thisAddress+"\n"+tos+ccs+ebcc); if (thisAddress.lastIndexOf('<') > thisAddress.lastIndexOf('"')) thisAddress=thisAddress.substring(thisAddress.lastIndexOf('<')+1,thisAddress.lastIndexOf('>')); if (thisAddress.lastIndexOf('@')!=-1) thisAddress=thisAddress.substring(0,thisAddress.lastIndexOf('@')); thisAddress = thisAddress.toLowerCase(); recipientsVector.addElement(thisAddress); lastComma=x; } } } if (ccToSelfCheckbox.getState()) { headersVector.addElement("From "+c.emailAddress()+" "+new Date().toString() +"\n"+cDate.getText().trim()+"\nSubject: "+cSubject.getText().trim()+"\nFrom: " +c.emailAddress()+"\nTo: "+c.emailAddress()+"\n"+tos+ccs+ebcc); recipientsVector.addElement("/self/"); } String[] recipientsArray = new String[recipientsVector.size()]; recipientsVector.copyInto(recipientsArray); String[] headersArray = new String[headersVector.size()]; headersVector.copyInto(headersArray); c.use(); wasSent = c.sendEncryptedMessage(recipientsArray,headersArray,cBody.getText(),false,"sent"); } /* If message should be sent plain text */ else { add(commands,commandsConstraints, new Label("Sending unencrypted message "),0,0); commands.paintAll(commands.getGraphics()); if (tos.length()>0) tos="To: "+tos.substring(0,tos.length()-2)+"\n"; if (ccs.length()>0) ccs="Cc: "+ccs.substring(0,ccs.length()-2)+"\n"; if (bccs.length()>0) bccs="Bcc: "+bccs.substring(0,bccs.length()-2)+"\n"; c.use(); c.sendPlainMessage(cDate.getText().trim()+"\nSubject: "+cSubject.getText().trim() +"\nFrom: "+c.emailAddress()+"\n"+tos+ccs+bccs,cBody.getText(),ccToSelfCheckbox.getState());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -