If I have an email with quoting:
and make a new email in Mail with NSSharingServiceItemsMBS and the html of the email I lose all quotes:
How can I get the quotes back? I tried some goggling where some said that blockquotes are supported. Others said that there are no blockquotes in an AttributedString. I tried with indentation but that also didn’t work.
How do you get your text into NSAttributedStringMBS class?
With your code from some weeks ago:
Dim documentAttributes As Dictionary
Dim documentOptions As New Dictionary
// define the text encoding
Const NSUTF8StringEncoding = 4
documentOptions.Value(NSAttributedStringMBS.NSCharacterEncodingDocumentOption) = NSUTF8StringEncoding
'// and a default base URL for finding images
'documentOptions.Value(NSAttributedStringMBS.NSBaseURLDocumentOption) = NSURLMBS.URLWithString("https://monkeybreadsoftware.de/")
// and a timeout for network queries
documentOptions.Value(NSAttributedStringMBS.NSTimeoutDocumentOption) = 30
Dim BodyAttributed As New NSAttributedStringMBS
call BodyAttributed.initWithHTML(theBody, documentOptions, documentAttributes)
'make email
Dim items As New NSSharingServiceItemsMBS
items.AddAttributedString(BodyAttributed)
Dim service As New NSSharingServiceMBS("com.apple.share.Mail.compose")
service.subject = theSubject
service.setRecipients theFromList.Concat(theCCList)
service.performWithItems items
When I copy text in Apple Mail and paste it in Textedit, there is no block quote.
I wonder whether this works at all.
The Mail app puts html on clipboard and uses a WebViewer to compose the email.
So I assume it can handle blockquote in text.
So no idea with blockquoting or indenting?
For newsletters I don’t care. But the usual chain emails look very odd when the quoting is not visible.
Well, NSMutableParagraphStyleMBS class has a headIndent property.
And you can add it to a NSMutableAttributedStringMBS with NSParagraphStyleAttributeName as name.
Maybe that helps to indent?
Thanks, I’ll try to make sense of the examples.
Should I be able to see some result with the following code in the action event of the button:
dim MutableString as new NSMutableAttributedStringMBS
if not MutableString.initWithString(testtext) then
MessageBox "string not initialised"
Return
end if
dim theRange as new NSRangeMBS(0, testtext.IndexOf(EndOfLine))
dim theStyle as new NSParagraphStyleMBS
dim MutableStyle as NSMutableParagraphStyleMBS = theStyle.mutableCopy
MutableStyle.setHeadIndent(4)
MutableStyle.setHeaderLevel(2)
MutableString.addAttribute(MutableString.NSParagraphStyleAttributeName, MutableStyle, theRange)
TextArea1.Text = MutableString.Text
@Christian_Schmitz : what am I doing wrong here?
With
TextArea1.Text = MutableString.Text
you certainly throw away all attributes by just moving plain text.
Let me check if I can get it working here better.
I got this:
Sub Opening() Handles Opening
Dim storage As NSTextStorageMBS = TextArea1.NSTextViewMBS.textStorage
Dim MutableString As NSMutableAttributedStringMBS = storage
Dim theRange As NSRangeMBS = New NSRangeMBS(0, TextArea1.Text.Length)
Dim MutableStyle As New NSMutableParagraphStyleMBS
MutableStyle.setHeadIndent(10)
MutableStyle.setFirstLineHeadIndent(20)
MutableString.addAttribute(MutableString.NSParagraphStyleAttributeName, MutableStyle, theRange)
End Sub
so looks like this with different intent for first and other lines:
Thanks. That works fine. But how do I change the style for a paragraph only? I’ve tried to reset the indent for the second text. But the email shows everything indented?
dim theBody as String = "blabla lkjf ösdjkf<br />"
theBody = theBody + "und noch mehr text lsdjfsdöfkj ösdlkjf södlkjf södlkfjsödlkfj"
Dim documentAttributes As Dictionary
Dim documentOptions As New Dictionary
// define the text encoding
Const NSUTF8StringEncoding = 4
documentOptions.Value(NSAttributedStringMBS.NSCharacterEncodingDocumentOption) = NSUTF8StringEncoding
'// and a default base URL for finding images
'documentOptions.Value(NSAttributedStringMBS.NSBaseURLDocumentOption) = NSURLMBS.URLWithString("https://monkeybreadsoftware.de/")
// and a timeout for network queries
documentOptions.Value(NSAttributedStringMBS.NSTimeoutDocumentOption) = 30
Dim MutableString As New NSMutableAttributedStringMBS
call MutableString.initWithHTML(theBody, documentOptions, documentAttributes)
Dim theRange As NSRangeMBS = New NSRangeMBS(0, 20)
Dim MutableStyle As New NSMutableParagraphStyleMBS
MutableStyle.setHeadIndent(10)
MutableStyle.setFirstLineHeadIndent(10)
MutableString.addAttribute(MutableString.NSParagraphStyleAttributeName, MutableStyle, theRange)
Dim theRange2 As NSRangeMBS = New NSRangeMBS(25, 40)
Dim MutableStyle2 As New NSMutableParagraphStyleMBS
MutableStyle2.setHeadIndent(0)
MutableStyle2.setFirstLineHeadIndent(0)
MutableString.addAttribute(MutableString.NSParagraphStyleAttributeName, MutableStyle2, theRange2)
'make email
Dim items As New NSSharingServiceItemsMBS
items.AddAttributedString(MutableString)
Dim service As New NSSharingServiceMBS("com.apple.share.Mail.compose")
service.subject = "theSubject"
service.setRecipients array("mail@beatrixwillius.de")
service.performWithItems items
You may want to check that the two NSRangeMBS objects are right.