<commit_before>//
//  SHSupportEmail.swift
//  SHSupportEmailDemo
//
//  Created by <NAME> on 12/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit
import MessageUI

public class SHSupportEmail: NSObject {
    
    var mailCompletionHandler: ((MFMailComposeResult, Error?) -> Void)?
    
    public func send(to recipients: [String], subject: String, from viewController: UIViewController, completion: ((MFMailComposeResult, Error?) -> Void)? = nil) {
        mailCompletionHandler = completion
        
        guard MFMailComposeViewController.canSendMail() else {
            mailCompletionHandler?(.failed, nil)
            return
        }
        
        let mailComposeViewController = MFMailComposeViewController()
        mailComposeViewController.mailComposeDelegate = self
        
        mailComposeViewController.setToRecipients(recipients)
        mailComposeViewController.setSubject(subject)
        mailComposeViewController.setMessageBody(generateEmailBody(), isHTML: false)
        
        viewController.present(mailComposeViewController, animated: true, completion: nil)
    }
    
    /// Generate the body of the email
    private func generateEmailBody() -> String {
        
        /// Initial new lines leave space for the user to write their own text
        var deviceInfo = "\n\n\n\n\n------------------\n"
        
        if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] {
            deviceInfo.append("App Version: \(version)\n")
        }
        
        deviceInfo.append("Device Model: \(UIDevice.current.model)\n")
        deviceInfo.append("System Version: \(UIDevice.current.systemName)\n")
        deviceInfo.append("System Locale: \(Locale.current.identifier)")
        
        return deviceInfo
    }
}

extension SHSupportEmail: MFMailComposeViewControllerDelegate {
<commit_msg>#1 added system version<commit_after>//
//  SHSupportEmail.swift
//  SHSupportEmailDemo
//
//  Created by <NAME> on 12/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit
import MessageUI

public class SHSupportEmail: NSObject {
    
    var mailCompletionHandler: ((MFMailComposeResult, Error?) -> Void)?
    
    public func send(to recipients: [String], subject: String, from viewController: UIViewController, completion: ((MFMailComposeResult, Error?) -> Void)? = nil) {
        mailCompletionHandler = completion
        
        guard MFMailComposeViewController.canSendMail() else {
            mailCompletionHandler?(.failed, nil)
            return
        }
        
        let mailComposeViewController = MFMailComposeViewController()
        mailComposeViewController.mailComposeDelegate = self
        
        mailComposeViewController.setToRecipients(recipients)
        mailComposeViewController.setSubject(subject)
        mailComposeViewController.setMessageBody(generateEmailBody(), isHTML: false)
        
        viewController.present(mailComposeViewController, animated: true, completion: nil)
    }
    
    /// Generate the body of the email
    private func generateEmailBody() -> String {
        
        /// Initial new lines leave space for the user to write their own text
        var deviceInfo = "\n\n\n\n\n------------------\n"
        
        if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] {
            deviceInfo.append("App Version: \(version)\n")
        }
        
        deviceInfo.append("Device Model: \(UIDevice.current.model)\n")
        deviceInfo.append("System Version: \(UIDevice.current.systemName) \(UIDevice.current.systemVersion)\n")
        deviceInfo.append("System Locale: \(Locale.current.identifier)")
        
        return deviceInfo
    }
}

extension SHSupportEmail: MFMailComposeViewControllerDelegate {

{'fraction_non_alphanumeric': 0.10380803338549817, 'fraction_numerical': 0.005477308294209703, 'mean_word_length': 2.7160852713178296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3499825', 'n_tokens_mistral': 1033, 'n_tokens_neox': 980, 'n_words': 234}