@@ -543,6 +543,28 @@ public override void SaveAs(string path, string extension, bool append = false)
543543 }
544544
545545
546+ public class CalendarContent : TextLikeContent {
547+ public static readonly string [ ] FORMATS = { "text/calendar" , "ics" , DataFormats . Text } ;
548+ public static readonly string [ ] EXTENSIONS = { "ics" } ;
549+
550+ public CalendarContent ( string text ) : base ( FORMATS , EXTENSIONS , text ) { }
551+
552+ public override string Description => string . Format ( Resources . str_preview_calendar ,
553+ Text . ToUpperInvariant ( ) . Split ( '\n ' ) . Count ( l => l . Trim ( ) . StartsWith ( "BEGIN:VEVENT" ) ) ) ;
554+
555+ public override void AddTo ( IDataObject data ) {
556+ // Note: Spec says UTF8 is the default, but thunderbird only accepts UTF16 (simply called "Unicode" in .NET)
557+ AddTo ( data , Text , Encoding . Unicode ) ;
558+ }
559+
560+ public override void SaveAs ( string path , string extension , bool append = false ) {
561+ if ( append ) throw new AppendNotSupportedException ( ) ;
562+ base . SaveAs ( path , extension , append ) ;
563+ }
564+
565+ }
566+
567+
546568 public class FilesContent : BaseContent {
547569 public FilesContent ( StringCollection files ) {
548570 Data = files ;
@@ -792,7 +814,8 @@ public static ClipboardContents FromClipboard() {
792814 if ( ReadClipboardString ( RtfContent . FORMATS ) is string rtf ) container . Contents . Add ( new RtfContent ( rtf ) ) ;
793815 if ( ReadClipboardString ( DifContent . FORMATS ) is string dif ) container . Contents . Add ( new DifContent ( dif ) ) ;
794816 if ( ReadClipboardString ( SvgContent . FORMATS ) is string svg ) container . Contents . Add ( new SvgContent ( svg ) ) ;
795-
817+ if ( ReadClipboardString ( CalendarContent . FORMATS ) is string ics && ics . ToUpperInvariant ( ) . StartsWith ( "BEGIN:VCALENDAR" ) )
818+ container . Contents . Add ( new CalendarContent ( ics ) ) ;
796819
797820 if ( Clipboard . ContainsText ( ) && Uri . IsWellFormedUriString ( Clipboard . GetText ( ) . Trim ( ) , UriKind . Absolute ) )
798821 container . Contents . Add ( new UrlContent ( Clipboard . GetText ( ) . Trim ( ) ) ) ;
@@ -932,12 +955,8 @@ public static ClipboardContents FromFile(string path) {
932955 container . Contents . Add ( new SvgContent ( contents ) ) ;
933956 if ( ext == "csv" )
934957 container . Contents . Add ( new CsvContent ( contents ) ) ;
935- if ( ext == "dif" )
936- container . Contents . Add ( new GenericTextContent ( DataFormats . Dif , ext , contents ) ) ;
937- if ( ext == "rtf" )
938- container . Contents . Add ( new GenericTextContent ( DataFormats . Rtf , ext , contents ) ) ;
939- if ( ext == "syk" )
940- container . Contents . Add ( new GenericTextContent ( DataFormats . SymbolicLink , ext , contents ) ) ;
958+ if ( ext == "ics" )
959+ container . Contents . Add ( new CalendarContent ( contents ) ) ;
941960 if ( DifContent . EXTENSIONS . Contains ( ext ) )
942961 container . Contents . Add ( new DifContent ( contents ) ) ;
943962 if ( RtfContent . EXTENSIONS . Contains ( ext ) )
0 commit comments