diff --git a/enzevalos_iphone/Base.lproj/Main.storyboard b/enzevalos_iphone/Base.lproj/Main.storyboard index e94afa8c8b00e714f211d178ebb91e01b4971000..ba61e611c3eb214823adc925529e0460b92e646c 100644 --- a/enzevalos_iphone/Base.lproj/Main.storyboard +++ b/enzevalos_iphone/Base.lproj/Main.storyboard @@ -705,15 +705,15 @@ <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalCentering" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="OlN-1g-hBJ"> <rect key="frame" x="21" y="38.5" width="15" height="24"/> <subviews> - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="imI-nB-es5"> - <rect key="frame" x="0.0" y="0.0" width="15" height="9"/> + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="imI-nB-es5"> + <rect key="frame" x="0.0" y="0.0" width="15" height="15"/> <constraints> <constraint firstAttribute="height" constant="15" id="NJi-27-Up8"/> <constraint firstAttribute="width" constant="15" id="auJ-Nm-E8J"/> </constraints> </imageView> - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="C7X-Yt-kz2"> - <rect key="frame" x="0.0" y="9" width="15" height="15"/> + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="C7X-Yt-kz2"> + <rect key="frame" x="0.0" y="15" width="15" height="9"/> <constraints> <constraint firstAttribute="width" constant="15" id="Sjh-9U-pfX"/> <constraint firstAttribute="height" constant="15" id="sLj-Te-fV3"/> @@ -1223,7 +1223,7 @@ <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> - <button key="tableFooterView" opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="KaX-Vg-m5j"> + <button key="tableFooterView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="KaX-Vg-m5j"> <rect key="frame" x="0.0" y="425.5" width="320" height="44"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="15"/> @@ -1393,7 +1393,7 @@ <objects> <tableViewController id="7Pd-d5-0wz" customClass="ExportInfoViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" dataMode="prototypes" style="grouped" separatorStyle="default" sectionIndexMinimumDisplayRowCount="1" rowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="2Uv-bd-pB1"> - <rect key="frame" x="0.0" y="0.0" width="320" height="504"/> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> <prototypes> @@ -1921,6 +1921,7 @@ Um deine sicheren E-Mails auch auf einem anderen Gerät lesen zu können, muss d <outlet property="toText" destination="zgt-Nh-yna" id="VXM-m0-UCm"/> <segue destination="8Di-x2-cWQ" kind="show" identifier="showContact" id="DcR-GX-scc"/> <segue destination="olx-gF-WdV" kind="presentation" identifier="inviteSegue" id="QXm-7K-984"/> + <segue destination="olx-gF-WdV" kind="presentation" identifier="inviteSegueStudy" id="Sm1-yp-Umv"/> </connections> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="Lv5-U9-uUg" userLabel="First Responder" sceneMemberID="firstResponder"/> @@ -1961,7 +1962,7 @@ Um deine sicheren E-Mails auch auf einem anderen Gerät lesen zu können, muss d </scene> </scenes> <inferredMetricsTieBreakers> - <segue reference="QXm-7K-984"/> + <segue reference="Sm1-yp-Umv"/> <segue reference="td8-VW-Wrt"/> <segue reference="DcR-GX-scc"/> <segue reference="TgN-rB-esa"/> diff --git a/enzevalos_iphone/Logger.swift b/enzevalos_iphone/Logger.swift index dced1687f5f6ce428eda3973e0697adedc857af1..ee00a439a20c628e2155deecf84ad3fbf7a4ee29 100644 --- a/enzevalos_iphone/Logger.swift +++ b/enzevalos_iphone/Logger.swift @@ -394,7 +394,7 @@ class Logger { sendCheck() } - static func log(sent from: Mail_Address, to: [Mail_Address], cc: [Mail_Address], bcc: [Mail_Address], subject: String, bodyLength: Int, isEncrypted: Bool, decryptedBodyLength: Int, decryptedWithOldPrivateKey: Bool = false, isSigned: Bool, isCorrectlySigned: Bool = true, signingKeyID: String, myKeyID: String, secureAddresses: [Mail_Address] = [], encryptedForKeyIDs: [String] = []) { + static func log(sent from: Mail_Address, to: [Mail_Address], cc: [Mail_Address], bcc: [Mail_Address], subject: String, bodyLength: Int, isEncrypted: Bool, decryptedBodyLength: Int, decryptedWithOldPrivateKey: Bool = false, isSigned: Bool, isCorrectlySigned: Bool = true, signingKeyID: String, myKeyID: String, secureAddresses: [Mail_Address] = [], encryptedForKeyIDs: [String] = [], inviteMailContent: String?) { if !logging { return @@ -419,6 +419,9 @@ class Logger { event["myKeyID"] = Logger.resolve(keyID: myKeyID) event["secureAddresses"] = Logger.resolve(mailAddresses: secureAddresses) //means the addresses, which received a secure mail event["encryptedForKeyIDs"] = Logger.resolve(keyIDs: encryptedForKeyIDs) + if let content = inviteMailContent { + event["inviteMailContent"] = content + } saveToDisk(json: dictToJSON(fields: event)) sendCheck() diff --git a/enzevalos_iphone/MailHandler.swift b/enzevalos_iphone/MailHandler.swift index 39d25c1c7d5ac6a77b0fd802c8959da6fff92c33..51461a6ba42d03e249537756e7d6436dd0fa569e 100644 --- a/enzevalos_iphone/MailHandler.swift +++ b/enzevalos_iphone/MailHandler.swift @@ -268,7 +268,7 @@ class MailHandler { } //logMail should be false, if called from Logger, otherwise - func send(_ toEntrys: [String], ccEntrys: [String], bccEntrys: [String], subject: String, message: String, sendEncryptedIfPossible: Bool = true, callback: @escaping (Error?) -> Void, loggingMail: Bool = false, isHTMLContent: Bool = false, warningReact: Bool = false) { + func send(_ toEntrys: [String], ccEntrys: [String], bccEntrys: [String], subject: String, message: String, sendEncryptedIfPossible: Bool = true, callback: @escaping (Error?) -> Void, loggingMail: Bool = false, isHTMLContent: Bool = false, warningReact: Bool = false, inviteMail: Bool = false) { if let useraddr = (UserManager.loadUserValue(Attribute.userAddr) as? String) { let session = createSMTPSession() @@ -360,7 +360,11 @@ class MailHandler { } } } - Logger.log(sent: fromLogging, to: toLogging, cc: ccLogging, bcc: bccLogging, subject: subject, bodyLength: (String(data: cryptoObject.chiphertext!, encoding: String.Encoding.utf8) ?? "").count, isEncrypted: true, decryptedBodyLength: ("\n" + message).count, decryptedWithOldPrivateKey: false, isSigned: true, isCorrectlySigned: true, signingKeyID: sk.keyID!, myKeyID: sk.keyID!, secureAddresses: secureAddresses, encryptedForKeyIDs: keyIDs) + var inviteMailContent: String? = nil + if inviteMail { + inviteMailContent = message + } + Logger.log(sent: fromLogging, to: toLogging, cc: ccLogging, bcc: bccLogging, subject: subject, bodyLength: (String(data: cryptoObject.chiphertext!, encoding: String.Encoding.utf8) ?? "").count, isEncrypted: true, decryptedBodyLength: ("\n" + message).count, decryptedWithOldPrivateKey: false, isSigned: true, isCorrectlySigned: true, signingKeyID: sk.keyID!, myKeyID: sk.keyID!, secureAddresses: secureAddresses, encryptedForKeyIDs: keyIDs, inviteMailContent: inviteMailContent) } // } @@ -400,7 +404,11 @@ class MailHandler { //TODO add logging call here for the case the full email is unencrypted if unenc.count == allRec.count && !loggingMail { // Logger.queue.async(flags: .barrier) { - Logger.log(sent: fromLogging, to: toLogging, cc: ccLogging, bcc: bccLogging, subject: subject, bodyLength: ("\n" + message).count, isEncrypted: false, decryptedBodyLength: ("\n" + message).count, decryptedWithOldPrivateKey: false, isSigned: false, isCorrectlySigned: false, signingKeyID: "", myKeyID: "", secureAddresses: [], encryptedForKeyIDs: []) + var inviteMailContent: String? = nil + if inviteMail { + inviteMailContent = message + } + Logger.log(sent: fromLogging, to: toLogging, cc: ccLogging, bcc: bccLogging, subject: subject, bodyLength: ("\n" + message).count, isEncrypted: false, decryptedBodyLength: ("\n" + message).count, decryptedWithOldPrivateKey: false, isSigned: false, isCorrectlySigned: false, signingKeyID: "", myKeyID: "", secureAddresses: [], encryptedForKeyIDs: [], inviteMailContent: inviteMailContent) // } } sendOperation.start(callback) diff --git a/enzevalos_iphone/SendViewController.swift b/enzevalos_iphone/SendViewController.swift index e090d4eafa4f8f617f879c46d7649f44e9271b9e..cdec90b8f232b2819778f491ca745aedab37852c 100644 --- a/enzevalos_iphone/SendViewController.swift +++ b/enzevalos_iphone/SendViewController.swift @@ -54,6 +54,8 @@ class SendViewController: UIViewController { var prefilledMail: EphemeralMail? = nil var toField: String? = nil var sendEncryptedIfPossible = true + var freeTextInviationTitle = StudySettings.freeTextInvitationTitle + var freeTextInvitationCall: (() -> (String)) = StudySettings.freeTextInvitationCode var invite:Bool = false var invitationSelection = InvitationSelection() @@ -281,6 +283,33 @@ class SendViewController: UIViewController { controller.prefilledMail = mail } + } else if segue.identifier == "inviteSegueStudy" { + let navigationController = segue.destination as? UINavigationController + if let controller = navigationController?.topViewController as? SendViewController { + controller.invite = true + var to = [MailAddress]() + var cc = [MailAddress]() + for mail in toText.mailTokens { + if let mail = mail as? String { // , !EnzevalosEncryptionHandler.hasKey(mail) + to.append(DataHandler.handler.getMailAddress(mail, temporary: false)) + } + } + for mail in ccText.mailTokens { + if let mail = mail as? String { // , !EnzevalosEncryptionHandler.hasKey(mail) + cc.append(DataHandler.handler.getMailAddress(mail, temporary: false)) + } + } + + let mail = EphemeralMail(to: NSSet.init(array: to), cc: NSSet.init(array: cc), bcc: NSSet.init(), date: Date(), subject: NSLocalizedString("inviteSubject", comment: "Subject for the invitation mail"), body: "", uid: 0, predecessor: nil) + + + controller.prefilledMail = mail + let alert = UIAlertController(title: "abc", message: "xyz", preferredStyle: .alert) //TODO: @Olli add your Text here + alert.addAction(UIAlertAction(title: "OK", style: .cancel)) + DispatchQueue.main.async(execute: { + controller.present(alert, animated: true, completion: nil) + }) + } } } @@ -607,11 +636,12 @@ class SendViewController: UIViewController { if !UISecurityState { alert = UIAlertController(title: NSLocalizedString("Postcard", comment: "Postcard label"), message: sendEncryptedIfPossible ? NSLocalizedString("SendInsecureInfo", comment: "Postcard infotext") : NSLocalizedString("SendInsecureInfoAll", comment: "Postcard infotext"), preferredStyle: .alert) url = "https://userpage.fu-berlin.de/wieseoli/letterbox/faq.html#headingPostcard" - if subjectText.inputText() != NSLocalizedString("inviteSubject", comment: "") && !currentSecurityState { - alert.addAction(UIAlertAction(title: NSLocalizedString("inviteContacts", comment: "Allows users to invite contacts without encryption key"), style: .default, handler: { + if subjectText.inputText() != NSLocalizedString("inviteSubject", comment: "") && !currentSecurityState && !UserDefaults.standard.bool(forKey: "hideFreeTextInvitation") { + alert.addAction(UIAlertAction(title: freeTextInviationTitle, style: .default, handler: { (action: UIAlertAction) -> Void in + let segue = self.freeTextInvitationCall() // Logger.queue.async(flags: .barrier) { - Logger.log(close: url, mail: nil, action: "inviteSegue") + Logger.log(close: url, mail: nil, action: segue) // } self.performSegue(withIdentifier: "inviteSegue", sender: nil) })) @@ -722,7 +752,7 @@ class SendViewController: UIViewController { } DataHandler.handler.save(during: "invite") } - mailHandler.send(toEntrys as NSArray as! [String], ccEntrys: ccEntrys as NSArray as! [String], bccEntrys: [], subject: subject, message: message, sendEncryptedIfPossible: sendEncryptedIfPossible, callback: self.mailSend, isHTMLContent: (self.htmlMessage() != nil)) + mailHandler.send(toEntrys as NSArray as! [String], ccEntrys: ccEntrys as NSArray as! [String], bccEntrys: [], subject: subject, message: message, sendEncryptedIfPossible: sendEncryptedIfPossible, callback: self.mailSend, isHTMLContent: (self.htmlMessage() != nil), inviteMail: true) sendButton.isEnabled = false } } diff --git a/enzevalos_iphone/StudySettings.swift b/enzevalos_iphone/StudySettings.swift index c4ed4af1afef42f2b16380e3e247be8be68b04c2..5aaea95e14e0e35b7320b18783c3928c12fe8f82 100644 --- a/enzevalos_iphone/StudySettings.swift +++ b/enzevalos_iphone/StudySettings.swift @@ -63,6 +63,8 @@ class StudySettings { return invitationsmode == InvitationMode.Censorship || invitationsmode == InvitationMode.PasswordEnc } } + static var freeTextInvitationTitle = NSLocalizedString("inviteContacts", comment: "Allows users to invite contacts without encryption key") + static var freeTextInvitationCode: (() -> (String)) = {Void in return "inviteSegueStudy"/*use "inviteSegue" if there is no study present*/ } //return segue id to perform static let faqURL = "https://userpage.fu-berlin.de/wieseoli/letterbox/faq.html" static let raffleURL = "" static var studyID: String { @@ -158,6 +160,7 @@ class StudySettings { } let parameters = studyParameters + //TODO: @Olli set entry "hideFreeTextInvitation" in UserDefaults to true if needed // Logger.queue.async(flags: .barrier) { Logger.log(setupStudy: parameters, alreadyRegistered: !presentFirstQuestionaireMail, bitcoin: bitcoinMails)